Created
February 16, 2012 19:08
-
-
Save gma/1847073 to your computer and use it in GitHub Desktop.
Notes on reproducing association bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Card extends Serenade.Model | |
@localStorage = true | |
@property 'title', serialize: true | |
class CardSet extends Serenade.Model | |
@localStorage = true | |
@hasMany 'cards', as: (-> Card), constructor: Card, serializeIds: true | |
# Create one card, and one card set, and save them to the database. | |
the_set = new CardSet(id: 1) | |
the_set.save() | |
card = new Card(id: 1, title: 'hello') | |
card.save() | |
# Make a new CardSet (loaded from the database). | |
new_set = CardSet.find(1) | |
# This next line of code only updates the CardSet's list of cardIds if it gets | |
# run in the same "page load" as the CardSet was created in. | |
# | |
# To reproduce the problem, call localStorage.clear(), comment out the | |
# following line, and load a page that runs this code. You should see "0" in | |
# the console. Uncomment it and reload the page again, and you ought to see "1" | |
# in the console. You don't, you see "0". For some reason, cardIds isn't | |
# getting updated. | |
# | |
new_set.get('cards').push(card) | |
console.log CardSet.find(1).get('cards').length |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment