Possibility to access data from one store to another for accessors & mutators #341
-
In pinia you have the possibility to access other stores to use getters and setters Link //Parent
//Child
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
With custom repositories you can define what you like. import { Model } from "pinia-orm";
import { Adult } from "./Adult";
export class Person extends Model {
static entity = 'person';
static fields () {
return {
id: this.attr(null),
name: this.attr('')
adults: this.hasMany(Adult, 'person_id')
}
}
get checkForX () {
return this.name.toLowerCase().includes("x") || this.adults.map(adult => adult.extra_data).includes("x");
}
} Haven't tested the code above if it works. But i think you also need to make sure to eagerload the relation if you use this getter. |
Beta Was this translation helpful? Give feedback.
With custom repositories you can define what you like.
I think it should be possible to access related data with an getter. But i think the solution i post you is not very performant on big data.
The way you posted child doesn't make sense to access parent data. You need some relation inside the model and not importing the model.