Forum: Ruby on Rails Help with has_and_belongs_to_many relationships with paginat

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
318c5b8c776d147b65288b0899eea815?d=identicon&s=25 charlie.hubbard (Guest)
on 2005-11-12 12:49
(Received via mailing list)
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
A4b45b0467e28925b5103b50f7d39e5d?d=identicon&s=25 beattie.mark (Guest)
on 2005-11-14 08:35
(Received via mailing list)
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
This topic is locked and can not be replied to.