In the following hypothetical scenario, I''d like to associate Books
with Clubs without using finder_sql. Apparently, if you use
finder_sql, all the find_in_collection methods are not added to the
associated objects. Without which I won''t be able to call
my_club.books.find(:all, :conditions => ''is_read = true'')
or to do
pagination for example.
Class Club < ActiveRecord::Base
has_many :memberships
has_many :readers, :through => :memberships
#DOES NOT WORK
#has_many :books, :through => :readers
#DOES NOT ADD find_in_collection METHODS
#has_many :books, :finder_sql =>
# %q{
# select distinct books.*
# from books
# join memberships on books.reader_id
= memberships.reader_id and memberships.club_id = #{self.id}
# order by books.read_at desc
# }
end
Class Memberships < ActiveRecord::Base
belongs_to :club
belongs_to :reader
end
Class Reader < ActiveRecord::Base
has_many :memberships
has_many :books
end
Class Book < ActiveRecord::Base
belongs_to :reader
end
Does anyone have any idea how I can create this association without
rewriting the find_in_collection methods?
Thanks!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Perhaps I could write my own find method and extend the association proxy? Is there a more elegant way? On Jan 28, 12:58 pm, gsterndale <gsternd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> In the following hypothetical scenario, I''d like to associate Books > with Clubs without using finder_sql. Apparently, if you use > finder_sql, all the find_in_collection methods are not added to the > associated objects. Without which I won''t be able to call > my_club.books.find(:all, :conditions => ''is_read = true'') or to do > pagination for example. > > Class Club < ActiveRecord::Base > has_many :memberships > has_many :readers, :through => :memberships > > #DOES NOT WORK > #has_many :books, :through => :readers > > #DOES NOT ADD find_in_collection METHODS > #has_many :books, :finder_sql => > # %q{ > # select distinct books.* > # from books > # join memberships on books.reader_id > = memberships.reader_id and memberships.club_id = #{self.id} > # order by books.read_at desc > # } > end > > Class Memberships < ActiveRecord::Base > belongs_to :club > belongs_to :reader > end > > Class Reader < ActiveRecord::Base > has_many :memberships > has_many :books > end > > Class Book < ActiveRecord::Base > belongs_to :reader > end > > Does anyone have any idea how I can create this association without > rewriting the find_in_collection methods? > > Thanks!--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---