Forum: Ruby on Rails query returning just one value

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.
9f6e775366f2f607647fab8eeed66507?d=identicon&s=25 Vapor .. (vapor)
on 2009-05-05 10:24
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.
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-05-05 13:41
(Received via mailing list)
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 ..
9f6e775366f2f607647fab8eeed66507?d=identicon&s=25 Vapor .. (vapor)
on 2009-05-05 13:48
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!
9f6e775366f2f607647fab8eeed66507?d=identicon&s=25 Vapor .. (vapor)
on 2009-05-05 13:51
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
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-05-05 13:57
(Received via mailing list)
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 ..
9f6e775366f2f607647fab8eeed66507?d=identicon&s=25 Vapor .. (vapor)
on 2009-05-05 13:59
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 :)
A91bd6cef23eb3516245a092e196c4da?d=identicon&s=25 Maurício Linhares (mauricio)
on 2009-05-05 15:02
(Received via mailing list)
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 ..
This topic is locked and can not be replied to.