hello, i have the following query in an action @node_pages, @nodes = paginate(:nodes, :join => ["left join locations on nodes.location_id = locations.id where locations.loc_name like ''%#{@searchstring}%'' "], :per_page => 10) however i cant access the ID field, since NODES and LOCATIONS each have an ID field. how do i make sure i am accessing the ID field of the main table ? thanks adam
Adam Denenberg wrote:> hello, > > i have the following query in an action > > @node_pages, @nodes = paginate(:nodes, :join => ["left join locations > on nodes.location_id = locations.id where locations.loc_name like > ''%#{@searchstring}%'' "], :per_page => 10) > > however i cant access the ID field, since NODES and LOCATIONS each > have an ID field. how do i make sure i am accessing the ID field of > the main table ? > > thanks > adam > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > lists.rubyonrails.org/mailman/listinfo/rails >If this is mySQL then you can alias the second ID column EG: select nodes.*, locations.id ''locations_id'' from notes left join nodes.location_id = locations.id Not sure if that helps Geoff
i dont think u can do a custom query in a pages() function can you ? Is there away to alias with the current line the way it is ? Geoff wrote:> Adam Denenberg wrote: > >> hello, >> >> i have the following query in an action >> >> @node_pages, @nodes = paginate(:nodes, :join => ["left join locations >> on nodes.location_id = locations.id where locations.loc_name like >> ''%#{@searchstring}%'' "], :per_page => 10) >> >> however i cant access the ID field, since NODES and LOCATIONS each >> have an ID field. how do i make sure i am accessing the ID field of >> the main table ? >> >> thanks >> adam >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> lists.rubyonrails.org/mailman/listinfo/rails >> > If this is mySQL then you can alias the second ID column > EG: > select nodes.*, locations.id ''locations_id'' from notes left join > nodes.location_id = locations.id > > Not sure if that helps > > Geoff > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > lists.rubyonrails.org/mailman/listinfo/rails >
i think i actually saw somewhere where you can use a paginator custom sql query outside of the :conditions/:join options.. Anyone know how to do this ? I think I read somewhere in the Agile book about this same issue but i cant seem to find it. Adam Denenberg wrote:> i dont think u can do a custom query in a pages() function can you ? Is > there away to alias with the current line the way it is ? > > > Geoff wrote: > >> Adam Denenberg wrote: >> >>> hello, >>> >>> i have the following query in an action >>> >>> @node_pages, @nodes = paginate(:nodes, :join => ["left join locations >>> on nodes.location_id = locations.id where locations.loc_name like >>> ''%#{@searchstring}%'' "], :per_page => 10) >>> >>> however i cant access the ID field, since NODES and LOCATIONS each >>> have an ID field. how do i make sure i am accessing the ID field of >>> the main table ? >>> >>> thanks >>> adam >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> lists.rubyonrails.org/mailman/listinfo/rails >>> >> If this is mySQL then you can alias the second ID column >> EG: >> select nodes.*, locations.id ''locations_id'' from notes left join >> nodes.location_id = locations.id >> >> Not sure if that helps >> >> Geoff >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> lists.rubyonrails.org/mailman/listinfo/rails >> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > lists.rubyonrails.org/mailman/listinfo/rails >
On 9/27/05, Adam Denenberg <adam-fpx97dFL/ODYtjvyW6yDsg@public.gmane.org> wrote:> i think i actually saw somewhere where you can use a paginator custom > sql query outside of the :conditions/:join options.. Anyone know how to > do this ? > > I think I read somewhere in the Agile book about this same issue but i > cant seem to find it.Not sure if this helps for your specific issue, but for pagination with a custom result set I''ve uses the paginate_collection method found here... bigbold.com/snippets/posts/show/389 (Haven''t tested with very large result sets either) -- Jack Baty Fusionary Media - fusionary.com