miragejs / ember-cli-mirage

An Ember Addon to easily add Mirage JS to your Ember app.
http://ember-cli-mirage.com
MIT License
863 stars 441 forks source link

Polymorphics - missing the buid method #2568

Closed msucorey closed 9 months ago

msucorey commented 9 months ago

Ref https://miragejs.com/docs/main-concepts/relationships/, a model like 'comment' that has a polymorphic 'belongs to' commentable should have a createCommentable and buildCommentable method.

My models end up with only the create method (verified by inspecting the prototype). This almost serves the purpose, but if I try to instantiate the other model as an arg, I overflow the stack.

I need the build method so that I can use an existing instance of the model it will belong to and set the relationship up for testing.

Is this a bug? Or does it get fixed at some point past 1.1.8 - I couldn't tell from the docs. Also see https://github.com/miragejs/ember-cli-mirage/pull/1679.

cah-brian-gantzler commented 9 months ago

I have never used the polymorphic associations, didnt even know where in the code that it does that. After looking, I think its here https://github.com/miragejs/miragejs/blob/master/lib/orm/associations/belongs-to.js#L217 You can see there is a TODO to document it. But based on line 219 I think its newCommentable even though the docs say buildCommentable. I cant find in the code where build is preappended to anything.

msucorey commented 9 months ago

Ah thanks, yeah saw that method - will attempt using that.