You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In all the following cases I tried the following:
I created an author (POST /authors) and then I tried to create this authors' pictures (POST /authors/{ID}/pictures)
The shown example (case 1) gives me this error:
This gives me an TypeError: Cannot read property 'modelName' of null at Function.Model.belongsToRemoting ([…]/node_modules/loopback/lib/models/model.js:346:56).
I figured the following out:
As I wrote: Using Picture.hasMany(…, invert: true) and [Author | Reader].hasAndBelongsToMany(…) creates the right structure for the (through model) PictureLink(id, imageableType, imageableId, pictureId) but fails because of the error shown above. The error occurs because the belongsTo relation is broken.
Using Picture.hasAndBelongsToMany(…, invert:true ) and [Author | Reader].hasAndBelongsToMany(…) creates NOT the right structure for (id, imageableType, imageableId, pictureId, authorid , readerid) and it fails with the same error.
Using Picture.hasMany(…, invert:true ) and [Author | Reader].hasMany(…) creates NOT the right structure for (id) and it fails with an SQL Error because it tries the following query loopback:connector:postgresql SQL: INSERT INTO "public"."checkuupicturelink" () SELECT RETURNING "id"
@nvdnkpr thanks for reporting this, it is indeed a bug. Since the Picture can belong to either Author or Reader, relation.modelTo is not defined as a fixed value; it is dynamically deduced at runtime. The remoting setup that happens during Model.belongsToRemoting tries to access this though, and that is why it fails.
Activity
fabien commentedon Aug 7, 2014
@nvdnkpr thanks for reporting this, it is indeed a bug. Since the Picture can belong to either Author or Reader, relation.modelTo is not defined as a fixed value; it is dynamically deduced at runtime. The remoting setup that happens during Model.belongsToRemoting tries to access this though, and that is why it fails.
Could you please check if the fix at https://github.com/fabien/loopback/tree/fix/polymorphic-belongs-to solves this?
nvdnkpr commentedon Aug 7, 2014
I tried your fix and it worked. No error at all. Using the (1) setup from above (which is the one from the example).
I tried it with the postgres connector and also with my own connector for arangoDB