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

Model relation question #103

Open
kapso opened this issue Jan 19, 2014 · 1 comment
Open

Model relation question #103

kapso opened this issue Jan 19, 2014 · 1 comment

Comments

@kapso
Copy link

kapso commented Jan 19, 2014

Given the following models/relationship -

class Address
  include MotionModel::Model
  include MotionModel::ArrayModelAdapter

  columns street: :string, city: :string

  belongs_to :user
end

class User
  include MotionModel::Model
  include MotionModel::ArrayModelAdapter

  columns name: :string

  has_one :address
end

And this user hash:

{ "id"=>1, "name"=>"Steve", "address"=> { "id"=>1, "street"=>"2261 Market Street", "city"=>"San Francisco" } }

When I do the following User.new(user_hash).save the Address.count is still 0 ??

@sxross
Copy link
Owner

sxross commented Jan 19, 2014

We've heard about this use-case before but it didn't seem like a core MotionModel issue because it's a deserialization from external source task. The best way to accomplish this is to parse and stuff the data yourself. You may want to look at the Formotion code to see how creating objects from hashes is accomplished.

You are better able to know the relationships in your own code that MotionModel is at automagically inferring it.

If you come up with a generalized solution (maybe a recursion), that would be a really cool addition to MotionModel.

Thanks

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

No branches or pull requests

2 participants