Note that there are some explanatory texts on larger screens.

plurals
  1. POBackbone-relational fetchRelated not sending request
    primarykey
    data
    text
    <p>I'm using backbone.js and backbone relational 0.5.0 with a Rails 3.2 backend. I have a Card model which has_many Notes.</p> <p>Here are my JS models and collections:</p> <pre><code>Workflow.Collections.Cards = Backbone.Collection.extend({ model: Workflow.Models.Card, url: '/cards' }); Workflow.Models.Card = Backbone.RelationalModel.extend({ modelName : 'card', urlRoot : '/cards', relations: [ { type: Backbone.HasMany, key: 'notes', relatedModel: 'Workflow.Models.Note', collectionType: 'Workflow.Collections.Notes', includeInJSON: false, reverseRelation: { key: 'card', includeInJSON: 'id' } }] }); Workflow.Collections.Notes = Backbone.Collection.extend({ model: Workflow.Models.Note, url: '/cards/74/notes' // intentionally hard-coded for now }); Workflow.Models.Note = Backbone.RelationalModel.extend({ modelName : 'note', urlRoot : '/notes' }); </code></pre> <p>Normal fetching works great, but when I try fetchRelated in the console, I get an empty array:</p> <pre><code>card = new Workflow.Models.Card({id: 74}) // cool card.fetch() // hits the sever with GET "/cards/74" - works great card.fetchRelated('notes') // [] - didn't even try to hit the server </code></pre> <p>What's weird is that this works:</p> <pre><code>card.get('notes').fetch() // cool - GET "/cards/74/notes" </code></pre> <p>I <em>could</em> use that method and parse the response text, but it feels really dirty.</p> <p>Anyone know what I'm missing here?</p> <p>Thanks in advance, this one is really torturing me!</p> <p>Stu</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload