Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A model called Collection with a has_many relation #99

Open
jondoveston opened this issue Jan 2, 2014 · 3 comments
Open

A model called Collection with a has_many relation #99

jondoveston opened this issue Jan 2, 2014 · 3 comments

Comments

@jondoveston
Copy link

MotionModel relations dont seem to like using the name Collection and having a Collection has_many/belongs_to Items. Probably a collision with the internal collection method? Anyway not sure if this is a bug or a need for a reserved words list in the documentation.

@sxross
Copy link
Owner

sxross commented Jan 2, 2014

What error are you seeing? Can you provide a simple test case?

@jondoveston
Copy link
Author

Using the gem as it is on github master.

class Collection
  include MotionModel::Model
  include MotionModel::ArrayModelAdapter
  columns name: :string
  has_many :items, dependent: :destroy
end
class Item
  include MotionModel::Model
  include MotionModel::ArrayModelAdapter
  columns name: :string
  belongs_to :collection
end
c = Collection.create(name:'asdf')
c.items.create(name:'qwer')

results in error

model.rb:802:in `method_missing:': undefined method `<<' for Collection#1:0x96e4d50:Collection (NoMethodError)
        from array_model_adapter.rb:163:in `do_insert:'
        from model.rb:507:in `block in save_without_transaction:'
        from model.rb:541:in `call_hooks:'
        from model.rb:501:in `save_without_transaction:'
        from model.rb:494:in `save:'
        from array_finder_query.rb:194:in `create:'
=> #<NoMethodError: undefined method `<<' for Collection#1:0x96e4d50:Collection>

@sxross
Copy link
Owner

sxross commented Jan 3, 2014

Please try github branch issue99 to see whether this resolves your problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants