Replies: 1 comment
-
You can try something like this, although I don't recommend for readability and understanding of your DER class ModelA extends BaseModel {
@column({ isPrimary: true })
public id: number;
@column({ serializeAs: 'model_b_id' })
public modelBId: number
@hasOne(() => ModelA, { localKey: 'model_b_id', foreignKey: 'id' })
public modelB: HasOne<typeof ModelB>;
}
class ModelB extends BaseModel {
@column({ isPrimary: true })
public id: number;
@hasMany(() => ModelA, { localKey: 'id', foreignKey: 'model_b_id' })
public modelsA: HasMany<typeof ModelA>;
} |
Beta Was this translation helpful? Give feedback.
0 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.
-
Is this possible?
Or are you forced to call this a belongsTo in which case it must be the "child" model?
Right now with this as a hasOne, it is complaining that it is expecting
modelAId
to exist on CashWeighting.I know I could call this a belongsTo and things will work fine. Although a different ORM api is available for belongs_to vs. has_one, and the mental model of "who is the parent" is different, but that is just a mental abstraction.
I thought this hasOne setup was possible because of this answer given by Harminder: #1264
Beta Was this translation helpful? Give feedback.
All reactions