Closed RaphaelDDL closed 8 years ago
I might suggest you use this library: https://github.com/amccloud/backbone-dotattr if you require that functionality. I can't say for sure if this library will work out of the box however.
It makes it difficult to debug get()
calls using .get('foo.bar.baz')
in the case that foo
or bar
may not exist. Does an error get thrown? Does it just return null
instead? Should it return a promise and use getAsync()
instead?
Although I cannot comment on the exact reasoning why @PaulUithol originally removed this, I can see how a feature like this could spiral into some confusion for devs unsure of where in their chain of 'foo.bar.baz'
has the issue. When you call .get('foo').get('bar').get('baz')
you'll know exactly where the error occurs if one of those don't exist.
Hello :)
Not complaining, I just wanted to understand better about commit https://github.com/PaulUithol/Backbone-relational/commit/742796a804c2fe6ce2d077bb0c4948f7001aac26
So I'd like to ask you: Could you clarify why "Remove the dot notation syntax for getters; it just doesn't belong in the scope of BBR" ?
From my understanding, while isn't exactly a relational-specific feature, it does have it's merits since it's a "shorthand" version of
get
specially useful for accessing nested models.Without it, accessing something needs to be
this.model.attributes.this.attributes.that.attributes.key
(big lame 'n wrong way) or chain getsthis.model.get('this').get('that').get('key')
. But of course that means having to doif
s to test for each nested withhas
before actually callingget
. That's because a nested might not available (backend response for the relational key wasnull
so the relational model wasn't created, for example) and would throw an error of calling get on undefined.Sorry the question wasn't sooner. I just noticed this now that we upgraded relational to latest and code/tests broke. http://backbonerelational.org/#change-log didn't mention anything about the get so I had to go looking through the diffs/commits :P
Best Regards, Raphael