You probably want #pluck:

http://api.rubyonrails.org/classes/ActiveRecord/Calculations.html#method-i-pluck

-a.

On 15 Feb 2013, at 5:05 AM, Lorenz Blackbird <[email protected]> wrote:

> I have a many-to-many relationship in my course model in this way:
> 
> has_many :course_paragraphs
> has_many :paragraphs, :through => :course_paragraphs
> 
> I use an inner join to select the paragraphs of my course:
> 
> Paragraph.joins(:course_paragraphs => :course)
>        .where('course_paragraphs.course_id' => @course.id)
> 
> This works, but I want to select an array containing only the ids of
> paragraphs.
> 
> By this solution I get an error:
> 
> @p_ids = Paragraph.select(:id)
>                 .joins(:course_paragraphs => :course)
>                 .where('course_paragraphs.course_id' => @course.id)
> 
> Mysql2::Error: Column 'id' in field list is ambiguous: SELECT id FROM
> `paragraphs` INNER JOIN `course_paragraphs` ON
> `course_paragraphs`.`paragraph_id` = `paragraphs`.`id` INNER JOIN
> `courses` ON `courses`.`id` = `course_paragraphs`.`course_id` WHERE
> `course_paragraphs`.`course_id` = 1
> 
> By this solution, the array contain hexadecimal values:
> 
> @p_ids = Paragraph.select('paragrahs.id')
>                 .joins(:course_paragraphs => :course)
>                 .where('course_paragraphs.course_id' => @course.id)
> 
> Where in my problem?
> 
> Thanks to all.
> 
> -- 
> Posted via http://www.ruby-forum.com/.
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
> 
> 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to