Skip to content

Commit

Permalink
doc: add extra scopes info
Browse files Browse the repository at this point in the history
  • Loading branch information
wbotelhos committed Mar 1, 2018
1 parent 84e549b commit c279b62
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,26 @@ To order the rating you do the same thing:
Article.order_by_rating scope: category_1
```

### Extra Scopes

Maybe you need to use more than one scope to make a rate, so you can use the `extra_scopes` options.
This feature is enable **only** to restrict the rate, the rating calculation will **ignore** it.

Example situation: I have a Profile (resource) that belongs to some Category (scope) and the Client (author) will rate
this Profile based on each Lead (extra scope) this Profile made. The Client can vote just one time on each lead, but many
times to that Profile. The Profile has a rating score based on all leads made on that Category.

```ruby
scope = Category.first
author = Client.last
resource = Profile.last
lead = Lead.last

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.

### Records

Maybe you want to recover all records with or without scope, so you can add the suffix `_records` on relations:
Expand Down

0 comments on commit c279b62

Please sign in to comment.