Comments (8)
What would you expect the output of console.log to be?
from backbone-relation.
I edited the content of the issue to make this clear, it should be undefined
.
Here's a QUnit test for that, I'm taking a look at fixing it myself:
QUnit.test('doing an unset on a related model should remove it', 2, (assert) => {
const mPost = new MPost();
mPost.set('author', { id: 5, name: 'Burhan' });
assert.equal(mPost.get('author').get('id'), 5);
mPost.unset('author');
assert.equal(mPost.get('author'), undefined, '.unset should make the model undefined');
});
from backbone-relation.
Hm, I'm not sure that is how backbone-relation should work. One of backbone-relation's strengths is that it keeps the same model instance. As a result of this, listening in a view this.listenTo(this.model.get('user), 'change:id', this.blaat);
will always work.
Make sure you talk to @abzainuddin about this before fixing it.
from backbone-relation.
Oh, actually the output is incorrect, after an unset
, the model should have the default values again.
from backbone-relation.
The manual gives:
This implies that once a relation is set, it cannot be overridden with another value. If you do really want to set another instance for a relation, then first use unset:
mAuthor.unset('user');
mAuthor.set('user', mUser);
The original idea was that unset is the escape where you can really unset a relation, so:
mPost.unset('author');
should remove the author.
from backbone-relation.
Ah whoops, remembered it wrong.
@mdamien, even if you don't manage to fix it yourself, could you add the failing test?
from backbone-relation.
Hm, I'm not sure that is how backbone-relation should work. One of backbone-relation's strengths is that it keeps the same model instance. As a result of this, listening in a view this.listenTo(this.model.get('user), 'change:id', this.blaat); will always work.
@SpaceK33z I think the problem you're describing is better solved by the ability to do "deep listening". Like:
this.listenTo(this.model, 'change:user.id', this.blaat);
from backbone-relation.
The problem I'm describing is already solved with backbone-relation. Using unset
is still something you shouldn't do most of the times; instead better clear the model.
from backbone-relation.
Related Issues (1)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone-relation.