-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
update buildURLForHasMany hook #2435
Conversation
@igorT do you have time to check this out? What do you think of adding options to the hasMany definition explicitly setting up how the relationship is resolved (ids, links, primaryKey/foreignKey)? |
Crap, not sure how I missed this, will review asap |
@igorT yeah no worries. This is something that I am surprised is not a more sought after feature. |
a5b8c5a
to
5be1c1c
Compare
@igorT any word on this? Is there anything I can do to help this along? |
@arenoir holidays and crap came in between, reviewing now. Feel bad about leaving this hanging, happy to pair with you/screenshare on this or any other ED/Ember issue as a penance. |
@@ -549,6 +549,18 @@ export default Adapter.extend({ | |||
return url; | |||
}, | |||
|
|||
|
|||
|
|||
buildURLForHasMany: function(relationshipName, type, record) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure we want provide a default implementation, seems more like a fallback option?
I feel like instead of passing buildURL as an option, we should fallback to it if t is defined and the the server did not provide us with ids or with a url. |
this.updateLink(data.links[key]); | ||
} | ||
|
||
if (this.buildURL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically instead of the option, if no value and no link, we should set a flag that is 'generateLink' if there is a buildURLForHasMany in the adapter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can then check the flag at https://github.com/arenoir/data/blob/build-hasmany-url/packages/ember-data/lib/system/relationships/state/has_many.js#L188 instead of relying on there being a link
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And findLink
can then generate a link
if one is not provided
Again, apologies for taking this long, PRs like these are a bit scary and I suck :( |
@igorT you don't suck :) this is a overwhelming project. I am happy to be able to contribute. I will make the changes you noted and rebase. |
a3967b9
to
8677f0a
Compare
@igorT take a look when you get some time. The biggest change was moving the |
@@ -16,13 +16,24 @@ export function typeForRelationshipMeta(store, meta) { | |||
return type; | |||
} | |||
|
|||
export function generateLink(store, kind, type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not put it on the relationship class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be misunderstanding the use but I was thinking If i put here the function would be looked up only once when the relationship is defined rater than each time the record is updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure this makes a difference? You will call the function every time you want to generate a link no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes if the generateLink
function is found it will call the returned function every time but if the function is not found it is only called once.
|
okay cool I will add the |
8677f0a
to
8501340
Compare
@igorT okay I took care of the issues you mentioned. My tests pass, It looks like Travis ci is crapping out when running npm. |
351ed09
to
19be12b
Compare
@igorT take a look when you get some time. I think this is ready to go. |
dd04ccf
to
ca0c098
Compare
+1 this is going to hopefully solve one of the biggest hurdles we have when using ember-data IMHO. |
9d1cdeb
to
743dc9d
Compare
3f5e631
to
0cffbca
Compare
@bmac, @igorT, @fivetanley just brought this up to date with master. Has this pr been discussed? What is preventing it from being merged? Is there anything I can do? |
Is my understanding correct that this PR and #2898 are solving the same problem, but in different ways? |
Implementing RFC #4 looks like it would solve this problem. Will it land in 1.0? Until then I will keep this up to date. |
0cffbca
to
0ad054c
Compare
This pr looks good to me. 👍 It just needs a rebase and a review from @igorT. |
I will rebase it today. |
update restadapters buildURLForHasMany to use buildUrl merge upstream add run to failing test resolved conflicts update based on igor's comments check for type in generateLink update from master move generateLink into relationship class add execption to buildUrlForHasMany test fix context closure in generateLink function fix tests styling merge with master fix tests
4eaded8
to
ca02f54
Compare
@bmac, I have rebased. However there are two tests that fail because of the way I restructured the The failing tests test the absence of new record relationships. And I am guessing I like moving the logic of how to load the data into the relationship instance. So I guess the question is why shouldn't new records have empty relationships? @igorT any thoughts? Is this functionality that @tomdale originally implemented still sought after? |
Here is a work around. |
@igorT: Any update on this? |
@arenoir any chance you have time to rebase this pr and put it behind a feature flag? If no let me know and I can do the work to rebase it. |
@arenoir do you have time to rebase this pr and put it behind a feature flag? |
@bmac I don't know if this is necessary anymore? I am able to build the link for relationships within the models serializer normalize function. Let me know. I could possibly spend some time on this next week.
|
Thanks @arenoir. I'm willing to re-visit this in the future but for now I like the idea of building the link for relationships within the models serializer normalize function. |
This seems to have gone stale. If this is something we want, @bmac suggested it go behind a feature flag, if not we can leave this closed. |
Implement #2168 buildURLForHasMany hook on current build. It uses an explicit buildURL option rather than depending on links and ids being nil. I'm with @tomdale that a dsl is needed but I have needed/wanted this feature from day one.
@igorT let me know what you think #2162.