-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
RFC for reference unification #57
Conversation
Several concerns that were raised in the Slack room:
|
emberjs/data#2264 seems relevant |
I like this a whole lot, and it would solve many of the use cases where we today have unnecessary fetches against the server and/or usage of private APIs. I also agree that the drawbacks seems worth it as described. What I'm missing currently is details on how (and if) this will affect current APIs. Especially what Igor describes in point 2, about references not leaking into record arrays (see emberjs/data#2375 for a similar issue). As I see it, the current APIs should maintain only showing loaded records, and references should only show up when using the new reference APIs. Any and all template usage should only show loaded records. I think it would be helpful if this is more explicitly stated in the RFC (if this is indeed the intent). I also think what Igor describes in point 1 should be implemented if possible without increasing complexity too much. Being able to manipulate relationships based on reference would save a lot of API calls and increase performance in several apps I'm currently working on. |
Looks great! ⛵ We have a few places where we need to determining if a reference exist without triggering a server-fetch. This would allows us to move off the private APIs we're currently using. Not 100% related, but it would allow for a JSON-API adapter to sub-class |
The current proposal does not support mutation, but I would be happy to add it if people need it. Perhaps:
I don't understand how your example puts references in the DOM. Can you give me the JS code that produces this?
Can you flesh out the use-case?
This proposal doesn't address that case. Do you think it's important to solve it now? If so, I can give it some thought. |
|
More discussion on getting the ids in a template here as well: worth reviewing emberjs/data#3025 cc @chancancode |
Another use case is to want to bind to |
I used to do this the non-public (dirty) way with I'd like to quick-fix this with a dirty (or not) solution. |
*/ | ||
``` | ||
|
||
### `ids` |
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 think this should be id
as it is a belongsTo and will only have one id, thus not being plural ids
I really like the direction this is headed. It seems like a lot of things that were not possible using public APIs are now possible in JavaScript land. I'm wondering what this means in templates though; it seems like it may be a bit cumbersome to get these references yourself every time and define them in a routable component. API of my dreams: {{#if comment.isLoaded}}
your commentID is {{comment.id}}
{{else}}
<button {{action "load-comment"}}>
Load comment
</button>
{{/if}} With this current RFC, I don't think this is quite possible without always defining isLoaded, etc yourself in every component or every model. This RFC introduces good primitives; my question for @wycats and @igorT is can we make some nice sugar on top of this in a semver compatible way. |
@jdurand I am also looking for a quick fix to accessing foreign keys. Did you have any success? |
@arenoir no, I haven't had time to dig into this yet. |
@jdurand okay here is my "quick fix". Added overrode the normalizeAttributes hook in the serializer to copy the foreign key. IMO the foreign_key should be public and not be thrown away.
I think this a pretty standard use case. Hope this helps. |
This would be a great addition to Ember Data! ⛵ @wycats do you want to wait for more feedback, or is this RFC ready for activation? |
@sandstrom I'm happy with it, assuming it gets further iterated on over time to handle use-cases we missed in the initial design. |
@wycats Sounds great! I've tried to compile what people have said above (please add if I've missed something).
This would be very useful in our app, we're currently using private APIs[2]. I'd rather see a smaller implementation soon, than wait for the utopian RFC covering all use-cases. 😄 Carbon copy: @igorT @wecc @fivetanley 1. Leaking references into DOM {{! will this leak references? I don't think it will, but please correct me if I'm wrong}}
{{each post.commentReferences as |comment|}}
{{linkTo 'comment' comment.id}}
{{/each}} 2. Brittle Workaround // brittle workaround
model._internalModel._relationships.initializedRelationships[relName].canonicalState.length |
Friendly ping 😄 @igorT @wecc @fivetanley @wycats This is a great proposal that would solve a concrete pain in our app. On the checklist above, what are your thoughts? (It's a list of all things mentioned in this thread, I think this proposal is ready for the next stage as soon as you guys feel that they are resolved; can add to the list if something is missing) |
Should this be closed now, since emberjs/data#3303 is merged? |
merged as 074c798. thanks for the reminder @sandstrom! |
FYI, I just edited the above original post to make "Rendered" be a valid permalink. It was broken because it pointed at a file under |
Rendered