Replies: 2 comments
-
What you are expecting is not possible and neither it can be added to Lucid, since it makes things a lot less predictable. However, you can solve it quite easily within your controller. const person = auth.user!
await person.load('stats')
person.stats?.person = person If you want to keep it DRY, then you can simply add a method to your model as class Person extends BaseModel {
public async loadStats() {
const self = this as Person
await self.load('stats')
self.stats?.person = self
}
}
await person.loadStats() |
Beta Was this translation helpful? Give feedback.
-
Thanks @thetutlage - I already have something in place in regards to auto preloading, I just thought if there's something to get the data rather than preloading it all over again.. because let's say we use on query preload, this can potentially go in a inf loop. E.g. What is the impact on the database? Is that cached if values are unchanged or it is hitting the database every time? Sorry I haven't done any investigation in regards to this. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi folks
So here's the question if anyone was able to get it solved or around it:
Two models, Person and Stats.
Relationship is 1 to 1.
In Person
In Stat
In stat model I have a computed property:
For the above to work, I have to preload stat and person again which seem to be a bit dumb - otherwise
this.person
is null (since it is not preloaded)e.g.
If I output what person object gives me, it is person object having stats loaded and within stats, I have same person details loaded again.
My question is, how can I access
this.person
inside stat model without going back and forth preloading relationship that is already defined and pretty much loaded? since stat is being loaded by person anyway. Why do I need to go back? Anyway to get person object without preloading it back?Beta Was this translation helpful? Give feedback.
All reactions