I am using INNER JOIN and it is supposed to return more than one results but it only returns first element. How do I get all elements in an array? Also, in the same query I am using another INNER JOIN that is supposed to return one value only which is does. Thanks. -- Posted via http://www.ruby-forum.com/.
It''s hard to help you if you don''t show any code. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Tue, May 5, 2009 at 5:24 AM, Vapor .. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > I am using INNER JOIN and it is supposed to return more than one results > but it only returns first element. > How do I get all elements in an array? > Also, in the same query I am using another INNER JOIN that is supposed > to return one value only which is does. > > Thanks. > -- > Posted via http://www.ruby-forum.com/. > > > >
Maurício Linhares wrote:> It''s hard to help you if you don''t show any code.@dest = Destination.find_by_id(params[:id], :joins => "INNER JOIN cities ON cities.id = city_id INNER JOIN destination_images ON destination_images.destination_id = destinations.id AND destination_images.is_primary_photo = 1 INNER JOIN destination_tags ON destination_tags.destination_id = destinations.id", :select => ''destinations.*, cities.name as city_name, destination_images.url as image_url, destination_tags.tag_id as tag_id_list'' ) pretty messy though! -- Posted via http://www.ruby-forum.com/.
Vapor .. wrote:> Maurício Linhares wrote: >> It''s hard to help you if you don''t show any code. > > @dest = Destination.find_by_id(params[:id], :joins => "INNER JOIN cities > ON cities.id = city_id > INNER JOIN destination_images ON destination_images.destination_id = > destinations.id AND destination_images.is_primary_photo = 1 > INNER JOIN destination_tags ON destination_tags.destination_id = > destinations.id", > :select => ''destinations.*, cities.name as city_name, > destination_images.url as image_url, destination_tags.tag_id as > tag_id_list'' )tag_id_list is supposed to return an array -- Posted via http://www.ruby-forum.com/.
This query is never going to return an array, it''s going o return a single row (by the params[:id]) with the joined relations. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Tue, May 5, 2009 at 8:51 AM, Vapor .. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Vapor .. wrote: >> Maurício Linhares wrote: >>> It''s hard to help you if you don''t show any code. >> >> @dest = Destination.find_by_id(params[:id], :joins => "INNER JOIN cities >> ON cities.id = city_id >> INNER JOIN destination_images ON destination_images.destination_id >> destinations.id AND destination_images.is_primary_photo = 1 >> INNER JOIN destination_tags ON destination_tags.destination_id >> destinations.id", >> :select => ''destinations.*, cities.name as city_name, >> destination_images.url as image_url, destination_tags.tag_id as >> tag_id_list'' ) > > > tag_id_list is supposed to return an array > > -- > Posted via http://www.ruby-forum.com/. > > > >
Maurício Linhares wrote:> This query is never going to return an array, it''s going o return a > single row (by the params[:id]) with the joined relations.Yeah, any help would be appreciated :) -- Posted via http://www.ruby-forum.com/.
First you need to explain what you do want returned and your database structure. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Tue, May 5, 2009 at 8:59 AM, Vapor .. <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Maurício Linhares wrote: >> This query is never going to return an array, it''s going o return a >> single row (by the params[:id]) with the joined relations. > > Yeah, any help would be appreciated :) > -- > Posted via http://www.ruby-forum.com/. > > > >