On Dec 20, 6:32 pm, LeonS
<leonard.stellbr...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi, I''ve got a problem with a has_many :through association, i
cant
> call the u1.UsersProfileAttributes.find_by_ProfileAttribute_name
> ("icq") method, rails means that this method doesn''t
exist. The method
> u1.UsersProfileAttributes.find_by_ProfileAttribute_id(3) works
> correctly. u1 is a user object. I don''t know whats the problem,
> because my associations seems to be okay.
>
has_many :UserProfileAttributes etc... should really be
has_many :user_profile_attributes. Looks like you''re getting away with
it for now but you''re probably storing up trouble for now.
u1.UsersProfileAttributes.find_by_ProfileAttribute_name doesn''t work
because the users_profile_attributes tables doesn''t have a name column
( but it does have a ProfileAttribute_id so your second example does
work).
Fred
> Have a look:
>
> class ProfileAttribute < ActiveRecord::Base
> has_many :UsersProfileAttributes
> has_many :users, :through => :UsersProfileAttributes
> end
> class User < ActiveRecord::Base
> has_many :UsersProfileAttributes
> has_many :ProfileAttributes, :through => :UsersProfileAttributes
> end
> class UsersProfileAttribute < ActiveRecord::Base
> belongs_to :user
> belongs_to :ProfileAttribute
> end
>
> My Migration file:
>
> class CreateProfileAttributes < ActiveRecord::Migration
> def self.up
> create_table :profile_attributes do |t|
> t.string :name
> t.integer :profile_group_id
> t.timestamps
> end
> create_table :users_profile_attributes do |t|
> t.integer :user_id
> t.integer :ProfileAttribute_id
> t.string :value
> end
> end
> def self.down
> drop_table :profile_attributes
> drop_table :users_profile_attributes
> end
> end
--
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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.