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

update buildURLForHasMany hook #2435

Closed
wants to merge 1 commit into from

Conversation

arenoir
Copy link
Contributor

@arenoir arenoir commented Oct 29, 2014

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.

@arenoir
Copy link
Contributor Author

arenoir commented Oct 31, 2014

@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)?

@fivetanley
Copy link
Member

@arenoir thanks! sorry for the long delay. I'll ask @igorT to look at it, or we can bring it up at the next ember data meeting.

@igorT
Copy link
Member

igorT commented Dec 12, 2014

Crap, not sure how I missed this, will review asap

@arenoir
Copy link
Contributor Author

arenoir commented Dec 15, 2014

@igorT yeah no worries. This is something that I am surprised is not a more sought after feature.

@arenoir
Copy link
Contributor Author

arenoir commented Jan 4, 2015

@igorT any word on this? Is there anything I can do to help this along?

@igorT
Copy link
Member

igorT commented Jan 6, 2015

@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) {
Copy link
Member

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?

@igorT
Copy link
Member

igorT commented Jan 6, 2015

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) {
Copy link
Member

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

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

@igorT
Copy link
Member

igorT commented Jan 6, 2015

Again, apologies for taking this long, PRs like these are a bit scary and I suck :(

@arenoir
Copy link
Contributor Author

arenoir commented Jan 6, 2015

@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.

@arenoir arenoir force-pushed the build-hasmany-url branch from a3967b9 to 8677f0a Compare January 6, 2015 21:09
@arenoir
Copy link
Contributor Author

arenoir commented Jan 6, 2015

@igorT take a look when you get some time. The biggest change was moving the buildUrlForHasMany function to the relationshipFromMeta function. I think it would be beneficial to add the same functionality to belongsTo relationships buildUrlForBelongsTo. This would be useful when dealing with composite primary keys.

@@ -16,13 +16,24 @@ export function typeForRelationshipMeta(store, meta) {
return type;
}

export function generateLink(store, kind, type) {
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

@igorT
Copy link
Member

igorT commented Jan 6, 2015

buildUrlForBelongsTo seems like a right thing to do as well

@arenoir
Copy link
Contributor Author

arenoir commented Jan 6, 2015

okay cool I will add the buildUrlForBelongsTo and take care of the other notes.

@arenoir arenoir force-pushed the build-hasmany-url branch from 8677f0a to 8501340 Compare January 6, 2015 23:15
@arenoir
Copy link
Contributor Author

arenoir commented Jan 7, 2015

@igorT okay I took care of the issues you mentioned. My tests pass, It looks like Travis ci is crapping out when running npm.

@arenoir arenoir force-pushed the build-hasmany-url branch from 351ed09 to 19be12b Compare January 7, 2015 18:57
@arenoir
Copy link
Contributor Author

arenoir commented Jan 7, 2015

@igorT take a look when you get some time. I think this is ready to go.

@arenoir arenoir force-pushed the build-hasmany-url branch 3 times, most recently from dd04ccf to ca0c098 Compare January 7, 2015 19:33
@Myztiq
Copy link

Myztiq commented Jan 14, 2015

+1 this is going to hopefully solve one of the biggest hurdles we have when using ember-data IMHO.

@bmac bmac removed the team-review label Feb 13, 2015
@arenoir arenoir force-pushed the build-hasmany-url branch 2 times, most recently from 3f5e631 to 0cffbca Compare March 23, 2015 19:37
@arenoir
Copy link
Contributor Author

arenoir commented Mar 23, 2015

@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?

@wecc
Copy link
Contributor

wecc commented Mar 24, 2015

Is my understanding correct that this PR and #2898 are solving the same problem, but in different ways?

@arenoir
Copy link
Contributor Author

arenoir commented Mar 24, 2015

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.

@arenoir arenoir force-pushed the build-hasmany-url branch from 0cffbca to 0ad054c Compare March 26, 2015 22:03
@arenoir
Copy link
Contributor Author

arenoir commented Mar 26, 2015

@wecc I believe PR #2898 and RFC #4 make the buildUrl more customizable but still require relationship payload from the server.

This pr adds extra functionality to generate the hasMany link automatically using the type and foreign_key.

@bmac
Copy link
Member

bmac commented Jun 5, 2015

This pr looks good to me. 👍 It just needs a rebase and a review from @igorT.

@arenoir
Copy link
Contributor Author

arenoir commented Jun 5, 2015

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
@arenoir arenoir force-pushed the build-hasmany-url branch from 4eaded8 to ca02f54 Compare June 6, 2015 00:50
@arenoir
Copy link
Contributor Author

arenoir commented Jun 6, 2015

@bmac, I have rebased. However there are two tests that fail because of the way I restructured the setupRelationships function in packages/ember-data/lib/system/store.js line 2135.

The failing tests test the absence of new record relationships. And I am guessing record._relationships.get(key) lazily creates a relationship.

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?

@arenoir
Copy link
Contributor Author

arenoir commented Jul 13, 2015

Here is a work around.

https://gist.github.com/jamesarosen/79337a515f557d7e9cf6

@greyhwndz
Copy link
Contributor

@igorT: Any update on this?

@bmac
Copy link
Member

bmac commented Mar 27, 2016

@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.

@bmac
Copy link
Member

bmac commented Jun 24, 2016

@arenoir do you have time to rebase this pr and put it behind a feature flag?

@arenoir
Copy link
Contributor Author

arenoir commented Jun 28, 2016

@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.

#/serializers/job.js
function urlForAttachments(jobId) {
  return `/api/v2/private_attachments?job_id=${jobId}`;
}

export default ApplicationSerializer.extend({
  normalize(typeClass, hash, prop) {
    hash.links = {
      privateAttachments: urlForAttachments(hash.id)
    };
    return this._super(typeClass, hash, prop);
  }
});

@bmac
Copy link
Member

bmac commented Jul 11, 2016

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.

@stefanpenner
Copy link
Member

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.

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.

8 participants