Partially fixed many-to-many relationship issue
I think I have a fix for the many-to-many relationship issue people have been experiencing. Please don't merge this in though, as the code is pretty poor right now. To complete the code we just need a good way of determining if a given relationship's inverse attribute is a belongsTo or a hasMany. Currently I am doing that by checking if the last character is an 's' or not, which obviously is less than ideal. But it does seem to work.
TLDR: This code will work in a pinch if your models follow standard inflection (e.g. "users/user", but not "people/person").
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
:memo: Please visit https://cla.developers.google.com/ to sign.
Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.
What to do if you already signed the CLA
Individual signers
- It's possible we don't have your GitHub username or you're using a different email address on your commit. Check your existing CLA data and verify that your email is set on your git commits.
Corporate signers
- Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the Google project maintainer to go/cla#troubleshoot (Public version).
- The email used to register you as an authorized contributor must be the email used for the Git commit. Check your existing CLA data and verify that your email is set on your git commits.
- The email used to register you as an authorized contributor must also be attached to your GitHub account.
ℹ️ Googlers: Go here for more info.
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).
:memo: Please visit https://cla.developers.google.com/ to sign.
Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.
What to do if you already signed the CLA
Individual signers
- It's possible we don't have your GitHub username or you're using a different email address on your commit. Check your existing CLA data and verify that your email is set on your git commits.
Corporate signers
- Your company has a Point of Contact who decides which employees are authorized to participate. Ask your POC to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the Google project maintainer to go/cla#troubleshoot (Public version).
- The email used to register you as an authorized contributor must be the email used for the Git commit. Check your existing CLA data and verify that your email is set on your git commits.
- The email used to register you as an authorized contributor must also be attached to your GitHub account.
ℹ️ Googlers: Go here for more info.
I fortunately have a better way to detect the inverse relationship.
What about saving the associated _ids?
Is this what you mean by saving the associated IDs? The code below is what I'm using to save models with a many-to-many rel:
this.store.createRecord('club', { title: 'My Club' }).save().then(club => {
let member = this.store.createRecord('member', { name: 'Bob' });
member.clubs.pushObject(club);
member.save().then(savedMember => {
club.members.pushObject(savedMember);
club.save();
});
});
This requires saving the club model twice. I don't know 100% how Ember Data intended relationship fetching/saving to work, but are you implying that the associated IDs should be persisted automatically if a many-to-many relationship is detected?
@googlebot I signed it!
I think we can save the inverse record in a batch. I’ll look into this more, thanks for getting this kicked off.
@jamesdaniels Any plans to continue this work please?
@charlesfries is your solution tested enough that i can roll a custom fork and begin to leverage many to many relationships again?