Open fluxsaas opened 10 years ago
Hi @fluxsaas! Thanks for reporting, I'll take a look as well.
debugging further:
with 1.1.0, the 'add' callback is always called after model.associated_models().fetch()
https://github.com/pathable/supermodel/blob/master/supermodel.js#L213
with 1.0.0 it only called on first model.associated_models().fetch()
reverting to the old behavior by passing ´.fetch({reset: true})´ does not through any errors :)
well, i'm stuck. can't figure out the problem. i can confirm that it's not backbone throwing the 'add' event after fetch:
a = new Backbone.Collection()
a.fetch()
a.on('add', function(a){console.log(a)})
does not shows any callback. So sth. on supermodel's end...
a = model.associated_models()
a.on('add', function(a){console.log(a)})
a.fetch()
triggers the 'add' callback.
Any luck on this? I just upgraded Backbone and am having some of the same issues. Strangely enough, I don't get the TypeError you are getting but I am having issues with duplicate models and collections with exactly double the length.
@lapluviosilla well. no not really. i have posponed this issue for me.
i have the same issue with duplicate models. But only for one specific collection. e.g.:
bad:
users = Account.users()
users.fetch()
users.length # => 6, should be 3
good:
users = new Users()
users.url = "/api/account/#{@account.id}/users"
users.fetch()
users.length # => 3
i think
it's a config error on the association configuration (.many / .one) on my side. but i havn't figured it out yet....
@lapluviosilla
i might have found the issue. with the above example i have:
association setup:
Account.has()
.many "users",
User.has()
.one "account",
with the server side json:
{
id: 1
name: ''Karl'
account_id: 2
}
which results in the doublication. If i remove the account_id
from the json it works!
maybe it's the same problem?
Hey @braddunbar , i think i figured out the problem. Maybe you can have a look at the failing test in my commit: 74fe5851fbfb49b32ac309e2d9137101ab1d0e1b
The pull request https://github.com/pathable/supermodel/pull/69 suggest a fix. I've tested it only with unit tests.
Hey,
just notices a broken behavior after upgrading to backbone version 1.1
backbone throws the error
Uncaught TypeError: Cannot read property 'cid' of undefined
on line:
https://github.com/jashkenas/backbone/blob/master/backbone.js#L721
after debugging a while i found that fetching records with
model.associated_models().fetch()
throws this error, after executing 3-4 times :)it seems that supermodel just adds model after fetching (calling model.associated_models().length shows doubled length after each call) instead of replacing/resetting.
it seems that the new backbone functionality:
http://backbonejs.org/#upgrading
breaks supermodel.
i haven't found the right fix for supermodel yet. i gonna try :)