1

I am using Backbone Relational to handle relationships between two models that I have. Here are the two models that I have:

Thread = Backbone.RelationalModel.extend({
urlRoot: '/api/thread',
idAttribute: '_id',
relations: [{
    type: Backbone.HasMany,
    key: 'messages',
    relatedModel: 'Message',
    reverseRelation: {
        key: 'collection',
        includeInJSON: '_id',
    },
}]
});

The other model is:

Message= Backbone.RelationalModel.extend({
url: '/api/message',

});

Thread has an attribute called thread_name. This means that JSON of collection will be like

thread_name, messages: [message_title]

Now, I want a view like this

  1. Message_Title 1 in THREAD_A
  2. Message_Title 2 in THREAD_B
  3. Message_Title 3 in THREAD_A
  4. Message_Title 4 in THREAD_B

Now the question, how will be the View? This means, how can I access parent attribute name (i.e. ThreadName) in a Message_View?

P.S. : I am learning from the tutorial here http://antoviaque.org/docs/tutorials/backbone-relational-tutorial/

Please help!

Devesh Kumar
  • 1,009
  • 1
  • 17
  • 29

1 Answers1

0

have you tried (model.__super__) ?, this is supposed to get the parent model from which you extend. I am not sure about 'RelationalModel' and too lazy to do a jsfiddle!

  • Yes, I have tried. It does not work. However, the question is how we can access the attribute of one model from other model and vice versa using a foreign key like thing. There has to be some way I guess to access both sides of a relationship (with or without Backbone relational). – Devesh Kumar May 09 '13 at 14:10