How to have a hasOne relationship with a built-in always ratio

EmberJS removed hasOne in a previous edition. What is the way to create such a relationship of nested objects where I want to have hasOne

The removal of hasOne has been done in favor of attribTo, can anyone share a thought on how to write a {embedded: always} relationship between nested JSON.

+5
source share
2 answers

I know this question is old and answered, but since it is one of the best search results for "ember hasone" I wanted to share my findings on this issue. I read the link in the first answer, but the example is a bit outdated.

The built-in flag is deprecated, DS.RESTAdapter.map is not a function, and the DS.hasOne method is deprecated.

1.0.0-beta.2 hasOne "DS.belongsTo". , hasOne foreignKeys , ownTo.

: https://github.com/emberjs/data/commit/a466741a36731c5d382df33461268024627325ef

.

{"users": [{
  "id": 1,
  "name": "John Doe",
  "profile": 27,        // merged hasone
  "image": 3,           // merged hasone
  "account_id": 64      // an actual belongsTo
}]}

App.User = DS.Model.extend({
   name: DS.attr('string'),
   profile: DS.belongsTo('profile'),
   image: DS.belongsTo('image'),
   account_id: DS.belongsTo('account')
});

, , , hasOne

+14

, . .

+1

All Articles