PaulUithol / Backbone-relational

Get and set relations (one-to-one, one-to-many, many-to-one) for Backbone models
http://backbonerelational.org
MIT License
2.34k stars 330 forks source link

Problem defining relations: "model does not inherit from Backbone.RelationalModel" #578

Closed GerkinDev closed 5 years ago

GerkinDev commented 7 years ago

Hi, I'm trying to create a simple relation. My models are stored in a non-global scope that I've properly added to the config of the plugin.

My relation array config is as follow:

[
    {
        "key":"mainScene",
        "relatedModel":"scene",
        "type":"HasOne",
        "reverseRelation":
        {
            "key":"sketch",
            "model":"sketch"
        }
    }
]

And I got the following output...

Relation= Object { instance: Window → index.html, reverseRelation: Object, options: Object, key: "mainScene", keySource: "mainScene", keyDestination: "mainScene", model: Window → index.html, relatedModel: n() } : model does not inherit from Backbone.RelationalModel ( Window → file:///var/work/nodejs/alt_enter/index.html ).

I can't find a way to create a relation without throwing any errors. Can you please explain me what is wrong? Also, one strange point is that my config contains a reference to Window → file:///var/work/nodejs/alt_enter/index.html but it is serialized as 'sketch'

Backbone v1.3.3 Backbone Relational v0.10.0 Lodash (used instead of Underscore) v4.17.4

Thank you in advance for your help

bpatram commented 7 years ago

hi @Nihilivin can you create a jsfiddle (here is an example one you can work from: http://jsfiddle.net/4223kp5e/1/) to fully replicate your error? It will be easier to assist if I can see your model definitions and work from there!

By default the store will add window as a namespace to search. It's possible that no model scene is being found in the global namespace (window) but that should show a different error message than what you are seeing iirc.

GerkinDev commented 7 years ago

Here is the smallest example I've found so far: https://gist.github.com/Nihilivin/429433c07cb69450ada4619b32cce1b8 It works in jsfiddle, but in my environment (with previous setup) it throw an error every time.

So, yeah, this bug is environment-specific, but I can't see how to solve it. I tried using your backbone-relational.js file, the file in external resources of your fiddle, but nothing works... Where should I look?

Thank you for your attention

GerkinDev commented 7 years ago

Hi, Have you an idea of what's going on?

bpatram commented 7 years ago

@Nihilivin I'm unable to replicate your issue using the gist you sent. Here is what I used to try to replicate your issue: http://jsfiddle.net/0Lbfu0Le/2/ I am not having the issues you seem to be reporting.

If you can fork/modify that jsfiddle to report a failing unit test I will be better able to help!

bpatram commented 7 years ago

You should not need to define any model or relatedModel on a reverseRelation. Try removing that property in your relationship, it might cause issues (although, I can't say for certain off the top of my head).

GerkinDev commented 7 years ago

Tried this, no changes. But I have incoherent behaviors; I'll look at this deeper when I got the time and I keep you in touch.