In a rails app, I using the :finder_sql option in a has_many declaration. The rails docs say that when I do this, "find_in_collection is not added." What does this mean?
+2
A:
it means that when you have a has_many relationship between to tables like:
person has_many :books, :finder_sql
you wont get the person.books.find* methods you normaly would have gotten. the reason for this behavior is that activerecord cant easily compose the finder_sql with the find* methods you would be using, so it cant really give you that functionality
LDomagala
2009-02-04 00:31:04
+2
A:
This means that it doesn't support the method for finding an instance within a collection. The docs call it find_in_collection
(where "collection" is whatever the name of your association). An example might be more helpful here:
class Author < ActiveRecord::Base
has_many :posts
has_many :special_posts, :class_name => "Post",
:finder_sql => "SELECT * FROM posts WHERE ..."
end
author.find_in_posts(30) # it finds and returns post 30
author.find_in_special_posts(30) # not supported because finder_sql is used here.
Andrew Vit
2009-02-04 08:15:09
Hi avit,I'm not sure what you meant by "the method for finding an instance within a collection find_in_collection". In fact, I wasn't even sure how to parse that. Otherwise, your example would have made your answer better than Cyrik's.Dan
allyourcode
2009-02-06 02:29:42
Edited... hopefully that makes more sense now: I was referring to what the method was called in the docs, when it's actually a metaprogrammed method based on the name of your collection.
Andrew Vit
2009-02-06 19:35:05