it seems that my Coffeescript validation is not taken into account:
class PokerRange extends Backbone.Model
defaults:
id:0
cards:[[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12],[0..12]]
validate: (attributes) ->
if attributes.id<0 then "id should be positive"
window.firstrange= new PokerRange id:5
console.log window.firstrange.toJSON()
window.firstrange.set("id",-4)
console.log window.firstrange.toJSON()
This is the result:
Object {id: 5, cards: Array[13]}
Object {id: -4, cards: Array[13]}
I have found out why, I just forgot to pass as an option to the set method {validate:true}