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

allowing to pass an has many relationship on create record. Fixes #1497 #2400

Merged
merged 1 commit into from May 18, 2015
Merged

allowing to pass an has many relationship on create record. Fixes #1497 #2400

merged 1 commit into from May 18, 2015

Conversation

sly7-7
Copy link
Contributor

@sly7-7 sly7-7 commented Oct 20, 2014

Fixes #1497
cc/ @igorT

@sly7-7 sly7-7 changed the title allowing to pass an has many relationship on create record allowing to pass an has many relationship on create record. Fixes #1497 Oct 20, 2014
@@ -248,6 +248,7 @@ Store = Ember.Object.extend({
createRecord: function(typeName, inputProperties) {
var type = this.modelFor(typeName);
var properties = copy(inputProperties) || {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call _extractAttributes otherwise we will set the relationship twice. Maybe extract attributes, relationships and then warn if there is anything left?

@igorT
Copy link
Member

igorT commented Oct 22, 2014

Is this ready? Can you add some tests for the case where we have bunch of attrs and relationships together, to guard the case we discussed earlier.

@sly7-7
Copy link
Contributor Author

sly7-7 commented Oct 22, 2014

@igorT Sure, is https://github.com/emberjs/data/blob/master/packages/ember-data/tests/unit/store/create_record_test.js a good place to write them ?
Also, do you want some comments for the private _extract(attrs/rel) function ?

@igorT
Copy link
Member

igorT commented Oct 22, 2014

Comments would be nice, your call


// Set the properties specified on the record.
record.setProperties(attributes);
record._preloadData(relationships);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually preloadData handles attributes as well, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was thinking about that, but I'm not sure it has the same result as setProperties. For example I'm not sure that https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/model/model.js#L720 will trigger properties change. You should know more than me about that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I don't think we should use it for relationships as well actually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch actually, we shouldn't use it for relationships at all. The ED semantics are different, preloading means that data exists on server, if you createRecord it doesn't

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, actually when I read that: https://github.com/emberjs/data/blob/master/packages/ember-data/lib/system/model/model.js#L742, I thought it was exactly what we were looking for. So I was using preloadData for relationships only to use that path. (Also, it seemed to me that makes createRecord support passing relationships as ids as well).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So for now the behavior happens to end up the same because we don't do relationship change tracking, but once we do, we want preloading to not dirty while passing on create should

@sly7-7
Copy link
Contributor Author

sly7-7 commented Oct 22, 2014

Ok, I will do my best to do it this evening/night (busy until about 11pm GMT)

@igorT
Copy link
Member

igorT commented Oct 22, 2014

Thank you!

@sly7-7
Copy link
Contributor Author

sly7-7 commented Oct 22, 2014

Obviously, I think this needs more tests:

  • Corner cases (for example, setting hasMany with wrong value)
  • CreateRecord with async relationships

@sly7-7
Copy link
Contributor Author

sly7-7 commented Nov 25, 2014

@igorT I added some tests on setting hasMany relationship on a record. Let me know if this is still something we want (ie to fix #1497)

return relationship.getRecords();
}).meta(meta).readOnly();
}).meta(meta);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like it could backfire on us. @igorT thoughts to making this not readOnly?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model.set('posts', [post1, post2[) should work though?

@sly7-7
Copy link
Contributor Author

sly7-7 commented Mar 13, 2015

@igorT One more ping for you ;)

@bmac bmac modified the milestone: 1.0.0-beta.16 Mar 16, 2015
@sicasli
Copy link

sicasli commented May 14, 2015

+1

@igorT
Copy link
Member

igorT commented May 18, 2015

@sly7-7 sorry for the late response, this completely fell of my radar, until I saw @sicasli comment. Left a comment, really happy to see this merged soon. Thanks!

@sly7-7
Copy link
Contributor Author

sly7-7 commented May 18, 2015

@igorT rebased, updated using relationship.clear() and computedPolyfill. Though I don't know what to do with #2400 (comment)

@igorT
Copy link
Member

igorT commented May 18, 2015

Your rebase seems off by 1, it seems to have pulled another commit with it.

@igorT
Copy link
Member

igorT commented May 18, 2015

Otherwise looks good, ready to merge

@sly7-7
Copy link
Contributor Author

sly7-7 commented May 18, 2015

@igorT Thank for the review, do you want me to merge that after the right rebase ?

@igorT
Copy link
Member

igorT commented May 18, 2015

as long as travis passes

Using record's setProperties and making hasMany rel not read only anymore
@sly7-7
Copy link
Contributor Author

sly7-7 commented May 18, 2015

Ok, I don't know what was going on, but I had a commit about the beta.18 beeing released. This should be good now

igorT added a commit that referenced this pull request May 18, 2015
allowing to pass an has many relationship on create record. Fixes #1497
@igorT igorT merged commit 2f83303 into emberjs:master May 18, 2015
@igorT
Copy link
Member

igorT commented May 18, 2015

Thanks!

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

Successfully merging this pull request may close these issues.

store.createRecord + record.save do not resolve hasMany-Relationships
6 participants