maccman/spine — pull request #170 by bn1 (2011-12-30 01:10:42+00:00)
Title: added shortcut foreignKey (belongsTo and HasMany) and new manyToMany functionality

easy to use foreignKey and manyToMany functionality with html5 storage support

chicken = new Chicken name: 'Big Chicken'

egg1 = new Egg name: 'egg1', weight: 1
egg2 = new Egg name: 'egg2', weight: 2
egg3 = new Egg name: 'egg3', weight: 3
egg4 = new Egg name: 'egg4', weight: 4
egg5 = new Egg name: 'egg5', weight: 5

chicken.eggs().all()
>>> []

chicken.eggs().add egg1
chicken.eggs().all()
>>> [egg1]

chicken.eggs().add [egg2, egg3, egg4, egg5]
chicken.eggs().all()
>>> [egg1, egg2, egg3, egg4, egg5]

egg1.chicken()
>>> chicken

egg1.bigger().add [egg2, egg3, egg4, egg5]
egg2.bigger().add [egg3, egg4, egg5]
egg3.bigger().add [egg4, egg5]
egg4.bigger().add [egg5]

egg5.smaller().all()
>>> [egg1, egg2, egg3, egg4]

egg4.smaller().all()
>>> [egg1, egg2, egg3]

egg3.smaller().all()
>>> [egg1, egg2]

egg2.smaller().all()
>>> [egg1]