Skip to content

Commit

Permalink
doc: adds validations example
Browse files Browse the repository at this point in the history
  • Loading branch information
wbotelhos committed Mar 2, 2018
1 parent c279b62 commit 4c62090
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ author.rate resource, 5, extra_scopes: { lead_id: lead.id }, scope: scope

* The extra scopes fields is not present into gem, so you cannot use `{ lead: lead }`, for example.

All methods listed on [Scope](#scope) session allows `extra_scopes` as additional condition too.

### Records

Maybe you want to recover all records with or without scope, so you can add the suffix `_records` on relations:
Expand Down Expand Up @@ -360,13 +362,36 @@ You should just to provide a `config/rating.yml` file with the following content

```yml
rating:
rate_table: 'reviews'
rating_table: 'review_ratings'
rate_table: reviews
rating_table: review_ratings
```
Now the rates will be written on `reviews` table over `rating_rates` and calculation will be on `review_ratings` over `rating_ratings`.
You can change one table o both of them.

### Validations

#### Rate Uniqueness

Since you can to use [Extra Scopes](#extra_scopes) to restrict rates and the original model `Rating::Rate` is inside gem, you can configure the uniqueness validation, from outside, to include this extra scopes.

```yml
rating:
validations:
rate:
uniqueness:
case_sensitive: false
scope:
- author_type
- resource_id
- resource_type
- scopeable_id
- scopeable_type
- scope_1
- scope_2
```

## Love it!

Via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=X8HEP2878NDEG&item_name=rating) or [Patreon](https://www.patreon.com/wbotelhos). Thanks! (:

0 comments on commit 4c62090

Please sign in to comment.