-
Notifications
You must be signed in to change notification settings - Fork 33
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
Question: Embedded Documents #140
Comments
Are you using recent build from master? |
You also shouldn't need to specify an inverse in this case |
Also, what does |
I just checked out EPF and built it from the master branch yesterday. I agree that I shouldn't have to specify an explicit inverse in this case. On another model, doing that seemed to prevent EPF from sending invalid POSTs/PUTs. Here's the code:
|
Can you paste an example payload? On Thu, Jul 10, 2014 at 5:23 PM, David Patrick notifications@github.com
Gordon L. Hempton |
Which payload? A GET response? The POST/PUT requests? |
GET response, or both? On Thu, Jul 10, 2014 at 5:24 PM, David Patrick notifications@github.com
Gordon L. Hempton |
Seems like the explicit inverse doesn't break "findById" requests.... I'll get the responses now. |
Here's a response for a single item:
|
Hmm, I think this might be caused by the nested ability not having and id. On Thu, Jul 10, 2014 at 5:31 PM, David Patrick notifications@github.com
Gordon L. Hempton |
Here is a very truncated response from the server during a
|
Putting a static "id" of 1 in there made the exceptions go away. But the abilities also went away. |
Ah so I think the issue is that the abilities have a belongsTo on them. On Thu, Jul 10, 2014 at 5:56 PM, David Patrick notifications@github.com
Gordon L. Hempton |
Have you tried removing the belongsTo entirely from the ability?a On Thu, Jul 10, 2014 at 5:56 PM, David Patrick notifications@github.com
Gordon L. Hempton |
Yeah; then I get extra POST/PUT from EPF. |
At some point, I saw a comment in the EPF that said something about embedded documents requiring inverses... I could try to find it again. |
Particularly, line 49 of |
I might have made that unnecessary, but I think the safest solution for the short term would be to include the parent ID in the embedded model. Hopefully this can be cleaned up soon. |
I probably could do that.... But I have whole lot of Model types that make use of this pattern. Changing them all would be very time-consuming. Is there a slightly less safe tweak I could try out in the JavaScript, before resorting to that approach? |
You could create a custom Inside the HasMany serializer you could override the On Thu, Jul 10, 2014 at 6:11 PM, David Patrick notifications@github.com
Gordon L. Hempton |
Sounds good..... How do I register the custom HasMany serializer with EPF again? I know how to do it for a model. A HasMany override seems like it might be more explicit though. |
Unlike ember data, there is no distinction between a transform and a serializer (they are both just objects that have a serialize and a deserialize method) and they are looked up the same way. Looks like you aren't using EAK or ember-cli, so in your case you would just follow the right naming convention:
Cheers |
(edited to provide configurable implementation and example Model definitions) So, this seems to work: SO.ApplicationSerializer = Ep.ActiveModelSerializer.extend
extractProperty: (model, hash, name, type, opts) ->
if opts?.embedded && hash.id? && hash[name]?.length > 0
hash[name].forEach (m) =>
m[@_prop(name)]=hash.id
@_super(model, hash, name, type, opts)
_prop: (name) ->
(@configFor(name)?.inverse || @get('typeKey'))+'_id' And here are my Models:
I wasn't sure what extra data the See any downsides to this approach? |
Hmm at a glance it all looks like it could work out. Keep me posted as to how this plays out. |
What is the correct (and simplest) means of notifying EPF about Embedded Documents? Earlier, I thought that I had figured it out; but now, I'm running into the follow issue:
When going to the "foo.index" route, I get the following:
Anyone know what's going on?
Fyi - things seem to load fine when I don't specify an inverse. But then, EPF tries to POST/PUT the embedded document(s) separately.
Thanks.
The text was updated successfully, but these errors were encountered: