[v5] BelongsTo, preloading and associate() question #2224
-
So... I'm going to try to explain this, bear with me, I'm new at Adonis. I have a ProjectOwner Model (basically a "Company" so to speak), where I have a relationship to User as who owns it:
Question: AssociationWhen doing this:
I couldn't get it to associate a new ProjectOwner without defining the
Without that I got the following error: So, ¿Is it correct that I need to add the column |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
Yes, the model needs the foreignKeys to be available on the model itself. Infact, the To summarize it, Models form relationships with each other and not the database tables. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to make a composite key? |
Beta Was this translation helpful? Give feedback.
-
An example: @belongsTo(() => Invoices, { localKey: ['company_id, 'branch', 'store'], foreignKey: ['company_id, 'branch', 'store'] }) |
Beta Was this translation helpful? Give feedback.
-
I've just started with AdonisJS. Thank you all for such a beautiful framework. In KeysExtractor, I tried adding the column dynamically if the attribute doesn't exist already as follows and it worked. Would it be possible to incorporate this behavior into Lucid? Will this impact anything else?
|
Beta Was this translation helpful? Give feedback.
Yes, the model needs the foreignKeys to be available on the model itself. Infact, the
foreignKey
property inside relationship options is the name of the property on the model and not the table.To summarize it, Models form relationships with each other and not the database tables.