On Tuesday, January 13, 2015 at 6:45:23 PM UTC-8, Roy Lam wrote:
>
> Hi,
>
> In a many_to_many relationship, is it possible to cache retrieved record
> such that we get the 'reciprocal', e.g.
>
No.
> author = Author.where{:name=>"Einstein"}.first
> book = author.books.first
>
> written_by = book.authors.find{|a| a.name == "Einstein"}
>
When you do author.books, the most you can guess is that for each book,
books.authors would contain author somewhere in the array. You can't set
the reciprocal to [author], because it is likely that each book has other
authors. So you can't cache the reciprocal, you need to query the database
for to determine it.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.