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

Polymorphic associations #1080

Merged
merged 1 commit into from Jun 4, 2017
Merged

Polymorphic associations #1080

merged 1 commit into from Jun 4, 2017

Conversation

samselikoff
Copy link
Collaborator

No description provided.

@samselikoff samselikoff changed the title [wip] Polymorphic associations Polymorphic associations Jun 4, 2017
@samselikoff samselikoff merged commit 57be551 into master Jun 4, 2017
@samselikoff samselikoff deleted the polymorphic-associations branch June 4, 2017 01:28
@fran-worley
Copy link

fran-worley commented Jun 5, 2017

Could you add some documentation to what has changed with the inverse option? I've just upgraded to 0.3.3 to try out the new polymorphic associations and I'm running into inverse errors on code that ran fine in 0.3.2.

// models/committee.js
export default Model.extend({
  meetings: hasMany('meeting'), // access all meetings for committee
  nextMeeting: belongsTo('meeting')  // easily access the next meeting from meetings collection
});

// models/meetings.js
 export default Model.extend({
  committee: belongsTo({inverse: 'meetings'})
});

I now get: Mirage: The committee model has multiple possible inverse associations for the committee association on the meeting model.

@fran-worley
Copy link

It seems to work if I declare the inverse to nextMeeting as null, rather than putting an inverse on the hasMany:

// models/committee.js
export default Model.extend({
  meetings: hasMany('meeting'), // access all meetings for committee
  nextMeeting: belongsTo('meeting', {inverse: null})  // easily access the next meeting from meetings collection
});

// models/meetings.js
 export default Model.extend({
  committee: belongsTo()
});

@samselikoff
Copy link
Collaborator Author

@fran-worley I'm surprised that changed at all from 0.3.2 to 0.3.3 but glad you got it working again.

Are you using the auto-discover feature? Does it work if you get rid of your Mirage models?

@fran-worley
Copy link

I've just started doing so and it seems to be working ok, great feature 👍!

I more added my comment incase anyone else notices similar funny happenings.

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.

None yet

2 participants