-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
belongsTo needs to be redefined. #3696
Comments
Would you be able to explain a bit more what the issue is now compared to before? |
Well the biggest one is not being able to look up the foreign_key or rollback changes. |
With a belongsTo relationship the relationship is directly tied to the model. Unlike hasMany or hasOne where changing the relationship has no effect to the parent. |
The old internal format for a record with a belongsTo relationship was something like: {
"id": 1,
"author": 2
} The new one uses JSON API and the same representation as above now looks like: {
"data": {
"id": "1",
"type": "post",
"relationships": {
"author": {
"data": {
"id": "2",
"type": "user"
}
}
}
}
} How does this change how belongsTo relationships work? I'm just trying to understand the issue here, sorry if I'm missing something. |
Yes but moving the In previous versions of ember data rolling back a belongsTo relationship was straight forward as was filtering records by Fore example using the new format you could have a "belongsTo" relationship without a foreign_key by using just a link and no data hash.
|
It might be good for us to list the differences between has_one and belongs_to. They feel like the same thing to me but I don't know too much about hasOne. |
Hi @arenoir. I think this tread has some confusion about the definition of My understanding of this thread is that you are thinking of these terms in the mindset of a relational database. Where:
The As for the inability to rollback changes on |
You defined the difference between The problem with the current implementation is that if the payload has a foreign key ED creates the association and throws it out. If we say that Ember data makes no distinction between |
As already mentioned in #2705 and other issues, this will be possible once the implementation for RFC#57 is merged, which currently tracked at #3303. I will have time again starting in October to finalize this PR. Soon soon 😉 ... |
Given the following payload "hasOne" I don't see how it would be possible to retrieve the relationships id without loading the record.
vs a belongsTo relationship.
|
@arenoir It seems that I misunderstood your use case then. What I meant was your second sample above: the In your first payload above, I also don't see another way of getting the With the references API it will be possible to get the |
This is why I think there should be a difference between Since ED 1.13.0 belongsTo acts more like hasOne. The behaviors that I look for in a belongs to relationship.
I have implemented the rollback and marking the record dirty. However because there is no difference between hasOne and belongsTo changing a hasOne relationship IMO incorrectly marks the parent dirty. In my application I have to find a work around to getting the foreign_key without loading the record. Right now the only solution is to do it in the serializer and copy the key to another attribute.
|
Related: emberjs/rfcs#21 |
Since ember data moved to using json api as the internal data format I believe we lost the functionality of a belongs to relationship. Instead I would argue belongsTo is now a hasOne relationship. What happened to the
foreign_key
and why is it not considered a attribute?The text was updated successfully, but these errors were encountered: