adopted-ember-addons / adopted-ember-addons/ember-data-model-fragments

access 'parent' model

Abierto
#313 3 comentarios 1 reacción 0 asignados Ver en GitHub
Lenguaje dominante
TypeScript
Estrellas
367
Forks
108
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

let's have (like in the readMe)
```js
// 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()
});
```
```js
// 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 :

```js

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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Start with the README examples and the app/models/person.js and app/models/address.js snippets, then trace the addresses.createFragment entry point and the fragment owner behavior mentioned in the issue. Done means determining and documenting a supported way for an address instance to access its parent person without adding an explicit attribute or passing the parent during creation.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
javascript
Área
data
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.