Possibility to access data from one store to another for accessors & mutators #341
Answered
by
CodeDredd
whitespacecode
asked this question in
Q&A
|
In pinia you have the possibility to access other stores to use getters and setters Link //Parent //Child |
Answered by
CodeDredd
Sep 15, 2022
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. |
0 replies
Answer selected by
CodeDredd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.