
missing saved? when << a collection
Reported by Robert Sköld | November 27th, 2009 @ 10:05 AM
i have two models with has n through resource to each other: Tags and Post, and shouldn't this be possible to do?
post.tags << Tags.all( :name => ["yes","no"] )
i get this error:
NoMethodError: undefined method saved?' for
#<DataMapper::Collection:0x101b35248>
from /Users/slaskis/.gem/ruby/1.8/gems/extlib-0.9.13/lib/extlib/lazy_array.rb:418:in `method_missing'
from /Users/slaskis/.gem/ruby/1.8/gems/dm-core-0.10.1/lib/dm-core/collection.rb:1348:in `method_missing'
from /Users/slaskis/.gem/ruby/1.8/gems/dm-core-0.10.1/lib/dm-core/collection.rb:1207:in `resource_added'
from /Users/slaskis/.gem/ruby/1.8/gems/dm-core-0.10.1/lib/dm-core/associations/one_to_many.rb:314:in `resource_added'
from /Users/slaskis/.gem/ruby/1.8/gems/dm-core-0.10.1/lib/dm-core/collection.rb:467:in `<<'
from (irb):6
seems to me that i should be able to add a collection to a many-association.
and i believe this is where it all breaks? http://github.com/datamapper/dm-core/blob/next/lib/dm-core/collecti...
Comments and changes to this ticket
-
Dan Kubb (dkubb) November 27th, 2009 @ 12:36 PM
- State changed from new to not-applicable
The Collection#<< method accepts a Resource (or a Hash), not another Collection. If you wanted to concatenate two collections you'd use something like:
post.tags.concat(Tag.all(:name => %w[ yes no ]))
See the Collection#<< docs for more information: http://github.com/datamapper/dm-core/blob/master/lib/dm-core/collec...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »