How to specify dataType for relations (ie : @belongsTo()) #8476
Answered
by
achrinza
MartialSeron
asked this question in
Q&A
-
I know how to add MySQL dataType for a property but there is nothing in the doc about relations @model({
settings: {
indexes: {
groupIDX: {
keys: {
group: 1,
},
},
},
},
})
export class Test extends Entity {
@property({
type: 'string',
required: true,
})
name: string;
@property({
type: 'number',
id: true,
generated: true,
mysql: {
dataType: 'int unsigned',
},
})
id?: number;
@property({
type: 'string',
required: true,
})
url: string;
@belongsTo(() => Group, { name: 'groupTest' })
group: number;
constructor(data?: Partial<Test>) {
super(data);
}
} How can I specify |
Beta Was this translation helpful? Give feedback.
Answered by
achrinza
Apr 11, 2022
Replies: 1 comment 1 reply
-
The @belongsTo(
() => Group,
{name: 'groupTest'},
{
mysql: {
dataType: 'int unsigned',
},
},
)
group: number; More information can be found in the API docs. Hope it helps! |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
MartialSeron
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
@belongsTo()
decorator acceptsPropertyDefinition
as the third parameter. Hence it's possible to do this:More information can be found in the API docs.
Hope it helps!