charlie hubbard
2005-Nov-08 06:09 UTC
Help with has_and_belongs_to_many relationships with paginate?
I''m having trouble with the has_and_belongs_to_many relationship and using the paginate function. I''m trying to list all the Requests that have a particular Tag on them and paginate the results. Here is what I was doing before I tried to paginate. And BTW it works: @featureRequests = Request.find( :all, :conditions => "tags.id = #{@params[''id'']}", :order => @params[''sortBy''].nil? ? ''created_on'' : @params[''sortBy''], :include => :tags ) Here is what I tried to do with pagniate function @featureRequests_pages, @featureRequests = paginate( :request, :order => @params[''sortBy''].nil? ? ''requests.created_on'' : @params[''sortBy''], :per_page => 25, :include => ''tags'', :conditions => "tags.id = #{@params[''id'']}") So my model is Request has_and_belongs_to_many Tags and a Tag has_and_belongs_to_many Requests. (Don''t know if that is biting me or not). However, my condition to the paginate function can''t find the tags table. tags.id is an unknown table. It looks like it''s not joining my tables together. On a side note if I just list all the Requests it does work with the paginate function. I jsut can''t get it to honor the conditions. What am I missing? Thanks Charlie
Mark Beattie
2005-Nov-14 07:37 UTC
Re: Help with has_and_belongs_to_many relationships with paginate?
On Tuesday 08 November 2005 3:09 pm, charlie hubbard wrote:> I''m having trouble with the has_and_belongs_to_many relationship and > using the paginate function...Did you have any luck with that Charlie? I''ve just sunk a day''s development into trying to paginate complex table relationships without any success either. The custom/classic pagination method falls apart when you need SQL fragments to maintain table relationships and want to keep re-usable code. (DRY and all that). What do the pros do? Are we to believe that Basecamp and co. don''t use any 3-way join tables? -- Mark Beattie Easy Schedule Management http://easy-online-schedule.com