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

Embedded polymorphic record with custom id doesn't work. #2793

Closed
mayatskiy opened this issue Feb 16, 2015 · 7 comments
Closed

Embedded polymorphic record with custom id doesn't work. #2793

mayatskiy opened this issue Feb 16, 2015 · 7 comments
Labels
🏷️ bug This PR primarily fixes a reported issue

Comments

@mayatskiy
Copy link

If I have embedded polymorphic records and a custom primaryKey (for example '_id').
When I use EmbeddedRecordsMixin this code works incorrectly:

function extractEmbeddedHasManyPolymorphic(store, key, hash) {
  ...
  forEach(hash[key], function(data) {
    var typeKey = data.type;
    var embeddedSerializer = store.serializerFor(typeKey);
    var embeddedType = store.modelFor(typeKey);
    var primaryKey = get(embeddedSerializer, 'primaryKey'); // returns '_id'

    var embeddedRecord = embeddedSerializer.normalize(embeddedType, data, null);
    store.push(embeddedType, embeddedRecord);
    ids.push({ id: embeddedRecord[primaryKey], type: typeKey }); // the error is here
  });

next line:

   ids.push({ id: embeddedRecord[primaryKey], type: typeKey });

sets undefined id. Because embeddedRecord has no '_id' key after deserialization and have only 'id' key.

@mayatskiy mayatskiy changed the title Embedded polymorhic record with custon id doesn't work. Embedded polymorhic record with custom id doesn't work. Feb 16, 2015
@mayatskiy mayatskiy changed the title Embedded polymorhic record with custom id doesn't work. Embedded polymorphic record with custom id doesn't work. Feb 16, 2015
@lolmaus
Copy link
Contributor

lolmaus commented Feb 16, 2015

Hey @mayatskiy, i'm using polymorphic embedded records successfully. Can you please reproduce the issue on http://emberjs.jsbin.com/ ?

@mayatskiy
Copy link
Author

@lolmaus with custom id?

@lolmaus
Copy link
Contributor

lolmaus commented Feb 16, 2015

@mayatskiy, my polymorphic records are treated by the backend as nested attributes rather than child records. They arrive without ids.

I override the extractArray, extractSingle and serialize methods of the parent model serializer and slip ids into the polymorphic items.

@bmac
Copy link
Member

bmac commented Feb 16, 2015

Thanks for the bug report @mayatskiy. Would you like to open a pr to fix this issue?

@bmac bmac added the Bug label Feb 16, 2015
@igorT
Copy link
Member

igorT commented May 31, 2015

@pangratz wanna take a stab at this? Shouldn't be too hard, we in fact don't need to worry about the primary key here because we already normalized, so if you just remove those couple lines + a test would be good to go

@pangratz
Copy link
Member

@igorT I will take a stab at it tomorrow

@igorT
Copy link
Member

igorT commented Jun 2, 2015

Fixed by #3138

@runspired runspired added 🏷️ bug This PR primarily fixes a reported issue and removed Bug labels Sep 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bug This PR primarily fixes a reported issue
Projects
None yet
Development

No branches or pull requests

6 participants