Skip to content

access 'parent' model #313

Description

@ngouy

let's have (like in the readMe)

// app/models/person.js
import Model from 'ember-data/model';
import {
  fragment,
  fragmentArray,
  array
} from 'ember-data-model-fragments/attributes';

export default Model.extend({
  name      : fragment('name'),
  addresses : fragmentArray('address'),
  // titles    : array()
});
// app/models/address.js
import attr from 'ember-data/attr';
import Fragment from 'ember-data-model-fragments/fragment';

export default Fragment.extend({
  street  : attr('string'),
  city    : attr('string'),
  region  : attr('string'),
  country : attr('string')
});

Is there any way, from an address instance, to retrieve the person 'parent' without adding an attribute in the address model and passing it as a params when creating a new one :

import Address from 'models/address'
import DS from 'ember-data'

Address.reopen({
    person: attr() // or belongsTo ?? whatever
});

let person = store.getById('person', '1');
let addresses = person.get('addresses');

addresses.createFragment({
  street  : '1 Shy Maid',
  city    : 'Rhoyne River',
  region  : 'Free Cities',
  country : 'Essos',
  person: person // but  theoretically we already know that because it's created from a person instance ... 
});

// then I can laster on access my parent with
random_adress.person

edit : while checking the code, I know that we can access it through this._internalModel._owner but as "private keys", we can't use it as a computed property like this._internalModel._ower.my_pp. So it doesn't solved my issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions