TypeError: users.accountType is not a function [v4] #1658
Unanswered
punity-team
asked this question in
Help
Replies: 1 comment 2 replies
-
Hey @punity-team! 👋 This is not how you load relationships for multiple models at the same time. ▶ https://adonisjs.com/docs/4.1/relationships#_eager_loading |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I try to create a relationship between two tables.
One is users. They have a account type id for example 1 (free) as foreign key
One is account_types. They contain numbers like 1, 2, 3 like the primary key and then the role like free, pro etc.
Now I want to show the name of the role of it instead of the account_type_id
My Code:
In the Model:
accountType () { return this.hasOne('App/Models/AccountType') }
In the Controller:
const users = User.query().limit(15).fetch() return users.accountType()
When I execute:
TypeError: users.accountType is not a function
Beta Was this translation helpful? Give feedback.
All reactions