Skip to content

Commit

Permalink
Enhance the documentation of primary_key argument
Browse files Browse the repository at this point in the history
  • Loading branch information
khiav223577 authored Dec 27, 2019
1 parent 86823bc commit 702e3a6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,16 @@ Monitor on the specific model. Clean the cached objects if targets are changed.

### :primary_key

- Is needed to know which attribute should be passed to the parameter when using the instance `cacher`. For example, if a query, named `email_valid?`, uses `user.email` as parameter, and you call it from instance: `user.cacher.email_valid?`, pass `user.id` as the argument.
- Determine which column is going to pass to the query lambda, and to be part of the cache key.<br>
For example:

- **User.cache_at :arbitrary, ->(id){ id }**

The cache key will be `active_model_cachers_User_at_arbitrary_#{user.id}`

- **User.cache_at :arbitrary, ->(email){ email }, primary_key: :email**

The cache key will be `active_model_cachers_User_at_arbitrary_#{user.email}`

- Has the default value `:id`.

Expand Down

0 comments on commit 702e3a6

Please sign in to comment.