I'm trying to create a relationship between a City and a Person table in Adonis v5, so when i request the server to show a person, it would send as response the Person and the City object that is related to that Person. I already did a foreign key relationship in my pgdatabase.
Doing some research, I found that in Adonis v4 it would be something like this:
And this would be the index() response:
How can I do the same thing with Adonis v5? .with() does not work the same way in Adonis v5, so I don't know how to use it.
This is what I have done so far:
export default class Person extends BaseModel {
@belongsTo(() => City)
public city: BelongsTo<typeof City>
...
}
export default class PeopleController {
public async index() {
const people = await Person.all();
return people;
}
}
Sorry about the long post and thanks in advance.
Aucun commentaire:
Enregistrer un commentaire