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:
You don't need to do that. If you have a course in @course then its
paragraphs are just @course.paragraphs. It is rare to have to use
joins when working with Rails if you have got the associations right.
This works, but I want to select an array containing only the ids of
paragraphs.
I think this should work.
@course.paragraphs.select( :id )
You don't need to do that. If you have a course in @course then its
paragraphs are just @course.paragraphs. It is rare to have to use
joins when working with Rails if you have got the associations right.
You're right. I tried to resolve my problem in a different way and I'm
returned unintentionaly at the classic method with a long solution
I think this should work.
@course.paragraphs.select( :id )
Unfortunately it gave the same problem.
(:id) -> MySQL error
(:paragraphs => :id) -> hexadecimal values
I took the decision to keep the "hexadecimal" solution and adapt another
bit of my code to have same values.
You don't need to do that. If you have a course in @course then its
paragraphs are just @course.paragraphs. It is rare to have to use
joins when working with Rails if you have got the associations right.
This works, but I want to select an array containing only the ids of
paragraphs.
I think this should work.
@course.paragraphs.select( :id )
Colin
ActiveRecord actually gives you a method for exactly this: