If the User Model has the foreign key "extension_id" it''s not
has_on :extension
it has to be
belongs_to :extension
foreign keys are always on the belongs_to side. has_one/has_many has
no foreign keys.
On 30 Jun., 15:00, Jonas
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:> I got two models:
>
> Extension and User. User has a foreign key called extension_id.
> Extension has not key to user since it can be used by various models.
>
> My user model has "has_one :extension"
>
> Why do the following code fail?
> @user = User.find(params[:id])
> @user.extension.create
>
> Error:
> PGError: ERROR: column extensions.user_id does not exist
> RAD 1: SELECT * FROM extensions WHERE (extensions.user_id = 1) LIM...
> ^
> : SELECT * FROM extensions WHERE (extensions.user_id = 1) LIMIT 1
>
> -----------
>
> I do not understand why extension have to have a user_id? Can''t
> relations be one way?
>
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---