I don't believe you can set a relationship like that after it's
already been saved, unless you clear what's already there. The second
"@foo.bars = [Bar.new(:name => 'test'), {:name => '123'}]" would imply
that that all the other @foo.bars would be cleared of the association
in the db.

On Mar 15, 4:07 am, morbusg <[email protected]> wrote:
> Hi,
>
> require 'rubygems'
> require 'dm-core'
> DataMapper.setup(:default, 'sqlite3::memory:')
>
> class Foo
>   include DataMapper::Resource
>   property :id, Serial
>   property :name, String
>
>   has n, :bars
> end
>
> class Bar
>   include DataMapper::Resource
>   property :id, Serial
>   property :name, String
>
>   belongs_to :foo
> end
>
> DataMapper.auto_migrate!
>
> @foo = Foo.new(:name => 'baz')
> @foo.bars = [Bar.new(:name => 'lala'), {:name => 'diudiu'}]
>
> puts @foo.save
>
> @foo = Foo.first
> @foo.bars = [Bar.new(:name => 'test'), {:name => '123'}]
>
> puts @foo.save
>
> =>
> true
> false
>
> How is this meant to work?

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

Reply via email to