Hi!

Thanks for the reply. You're right, the plugin is working fine. I was
trying something like this: @account.update(params[:account]). This
params also  includes profile_attributes, but in my form I forgot to
put the profile's id as a hidden field. Now he's not creating another
profile. Everything works fine. Sorry!

Thanks,
Rodrigo Nicola
Twitter: http://www.twitter.com/rodnic



On Mon, Nov 8, 2010 at 1:52 PM, Jeremy Evans <[email protected]> wrote:
> On Nov 8, 6:27 am, Rodrigo Lombardo <[email protected]> wrote:
>> Hi
>>
>> I'm using the nested_attributes plugin and it's working fine. But when
>> I try to run the update method, the chield object is not saved. The
>> plugin is working just when I use the save method. A new child is
>> created when I try to update a current object and the existing related
>> object is nullified.
>>
>> My layout design is:
>>
>> Account model : one_to_one :profile; nested_attributes :profile
>>
>> Profile model: many_to_one :account
>>
>> Any ideas?
>>
>> Thanks,
>>
>> Rodrigo Nicola
>> twitter.com/rodnic
>
> This appears to work for me:
>
>
> require 'sequel'
> require 'logger'
> DB = Sequel.sqlite(:logger=>Logger.new($stdout))
>
> DB.create_table(:accounts) do
>  primary_key :id
>  String :name
> end
> DB.create_table(:profiles) do
>  primary_key :id
>  String :name
>  foreign_key :account_id, :accounts
> end
>
> class Account < Sequel::Model
>  one_to_one :profile
>  plugin :nested_attributes
>  nested_attributes :profile
> end
> class Profile < Sequel::Model
>  many_to_one :account
> end
>
> a = Account.create(:name => 'a')
> p = Profile.create(:name => 'p1', :account => a)
>
> a = Account.first
> a.update(:profile_attributes=>{:name => 'p2', :id=>p.id})
>
> p Account.all
> p Profile.all
>
>
> If it still isn't working for you, please include a self contained
> example like this one so I can troubleshoot.
>
> Jeremy
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sequel-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/sequel-talk?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-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/sequel-talk?hl=en.

Reply via email to