On Oct 11, 3:02 pm, cult hero <[email protected]> wrote:
> No, it's not pretty but I was gonna try something similar to that.
> (Although your method is far prettier than what I had in mind.)
>
> What I mean is... take this example.
>
> I grab all my articles that are filtered in a certain way. (Say, all
> articles that appear in a particular source.) Then, I select all
> authors using the same set of filters instead of throwing a huge IN
> statement at it with all the particular article IDs. Because authors
> are many to many I couldn't cram them all in one query. So I end up
> with, for example, 25 articles and 40 authors. I know, having run the
> queries, that all the authors I need to match those 25 articles are in
> that set of 40 authors.
>
> At this point when I loop through things I can have @articles and
> @authors and just run through them manually in a view. However, in a
> perfect world I'd rather be able to say, "Hey articles, all the
> authors you should be associated with here."
You can always manually modify the association cache for each article:
articles.each do |ar|
ar.associations[:authors] = ...
end
> I want to be able to say article.authors and have it work rather than
> have to work with the two datasets separately. (If I could specify the
> query that .eager uses that would do the trick.)
If you modify the association cache as above, then article.authors
would work and would use the cached version that you set manually.
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.