3

I am using Backbone-relational to have relational models. But i'm having a problem with related models of which the keys are in a nested attribute.

My model looks like this:

Event.Model = Backbone.RelationalModel.extend({
    urlRoot: "/events",

    defaults: {
      "id": null,
      "title": {
        "en": "Event name"
      },
      "related": {
        "actions": {}
        "resources": {
           "production": production_id
        }
      }
    },

    relations: [
      {
        type: Backbone.HasOne,  
        key: "related.resources.production",
        relatedModel: Production.Model,
        relatedCollection: Production.Collection,
        autoFetch: true
      }
    ]
});

What i am trying to achieve is: turn the Event.Model.related.resources.production into a Production.Model. The code above does not work.

When i fix it by implementing a Event.Model#parse() which takes Event.Model#related.resources.production and moves that to Event.Model#production, and i set the key in the "relations" to "production", it does work. But this seems like a really hacky solution.

Does this mean Backbone-relational doesn't understand the dotNotation in the key? Or am i doing something wrong?

jaapz
  • 989
  • 8
  • 26

0 Answers0