Closed rgant closed 8 years ago
This pull is in relation to #25
Just reviewing this im interested in the belongsTo
relationship you have created with a foreignKey.
Is this actually valid for a belongsTo
?
var Image = ds.defineResource({
name: 'image',
relations: {
belongsTo: {
article: {
localField: 'article',
foreignKey: 'imageid'
}
}
}
});
It's not valid, my bad. According to the documentation:
belongsTo uses "localField" and "localKey"
I don't think I am understanding what belongsTo means to js-data. I was thinking that the Article table would have SQL-like foreign key field to the Images table of the Image ID that it should display. An Image "belongs to" an Article in that case. But apparently that is not how js-data thinks of things. I think you are right that I just don't need belongsTo in my relations. I don't think it's giving me anything I would want.
What you are describing is a hasOne
relationship with a localKey on the parent.
With a localKey
you can:
Think of a belongsTo
as simply allowing you to traverse a hasOne
in the opposite direction.
In js-data this means the child has a property for accessing the related parent object.
And as mentioned earlier we can use this information to ensure that a parent is create before the child (this has not been done in js-data) though normally we would only be able to access child data via a parent, e.g. HATEOAS).
Created this pull request at @BlairAllegroTech's request. However I don't think he should import c065780
I just didn't quickly see how to not submit that part in the pull request.