Hi all,
It realy don''t work and all was ok like rails api sad.
@article = Article.new
@user = User.find(1) #test only
/ #### With this line all work perfectily!!/
#@article.users_id = @user.id
/ #### With this line I get an error when insert
#### record because it don''t set @article.users_id/
@article.user = @user
Tables names: users and articles
Class users has_many :articles
Class articles belongs_to :user
I really don''t know what is wrong!
Thank you
--
Pedro C. Valentini
pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org
+55 (21) 8708-8035
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
On 6/15/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> Hi all, > > It realy don''t work and all was ok like rails api sad. > > @article = Article.new > @user = User.find(1) #test only > > #### With this line all work perfectily!! > #@article.users_id = @user.id > #### With this line I get an error when insert > #### record because it don''t set @article.users_id > @article.user = @user > > Tables names: users and articles > Class users has_many :articles > Class articles belongs_to :user > > I really don''t know what is wrong! > Thank youThe name of your users model is User. Since (it seems) you have a :belongs_to relationship, the proper foreign key in your Articles model is user_id, not users_id. If your database has the name of that field as users_id, you''ll want to update it to user_id, and modify your above code to reflect that change. Hope that helps. Matt
Yes, thank you Matt
I confunded because our friend Duan sad it:
Plural:
* Database table names
* Fields used as Foreign Keys in the database (e.g. users_id)
* Associations of type "has_many" and
"has_and_belongs_to_many"
(e.g. has_many :items)
I want allert to others that the right is user_id!!
Thank you
Belorion escreveu:
>On 6/15/05, Pedro Valentini
<pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:
>
>
>> Hi all,
>>
>> It realy don''t work and all was ok like rails api sad.
>>
>> @article = Article.new
>> @user = User.find(1) #test only
>>
>> #### With this line all work perfectily!!
>> #@article.users_id = @user.id
>> #### With this line I get an error when insert
>> #### record because it don''t set @article.users_id
>> @article.user = @user
>>
>> Tables names: users and articles
>> Class users has_many :articles
>> Class articles belongs_to :user
>>
>> I really don''t know what is wrong!
>> Thank you
>>
>>
>
>The name of your users model is User. Since (it seems) you have a
>:belongs_to relationship, the proper foreign key in your Articles
>model is user_id, not users_id. If your database has the name of that
>field as users_id, you''ll want to update it to user_id, and modify
>your above code to reflect that change. Hope that helps.
>
>Matt
>_______________________________________________
>Rails mailing list
>Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
>
--
Pedro C. Valentini
pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org
+55 (21) 8708-8035
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
On Jun 15, 2005, at 3:12 PM, Pedro Valentini wrote:> Yes, thank you Matt > I confunded because our friend Duan sad it: > Plural: > * Database table names > * Fields used as Foreign Keys in the database (e.g. users_id) > * Associations of type "has_many" and > "has_and_belongs_to_many" (e.g. has_many :items) > I want allert to others that the right is user_id!!Thanks for correcting that! Duane Johnson (canadaduane)