when I use a quart joins on Roles and Profiles models
Role.joins(:profiles).where('profiles.profilable_type' => "Admin")
I get the following generated sql
SELECT `roles`.* FROM `roles` INNER JOIN `profiles_roles` ON
`profiles_roles`.`role_id` = `roles`.`id` INNER JOIN `profiles` ON
`profiles`.`id` = `profiles_roles`.`profile_id` WHERE
`profiles`.`profilable_type` = 'Admin'
which gives me all roles attributes only
I should I write my Rails query to get all attributes ?
SELECT `roles`.*, `profiles`.* FROM `roles` INNER JOIN
`profiles_roles` ON `profiles_roles`.`role_id` = `roles`.`id` INNER
JOIN `profiles` ON `profiles`.`id` = `profiles_roles`.`profile_id`
WHERE `profiles`.`profilable_type` = 'Admin'
in this case, I'll have 2 attributes with same name in both tables
( :id and :name ) is there any way to avoid such collision ( using
AS ...)
======
class Role < ActiveRecord::Base
has_and_belongs_to_many :profiles, :join_table => :profiles_roles
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.