ember 5.12
Joi 17.13.3
my emberjs model aModel
has a field which is defined like this:
@belongsTo('anotherModel', {async:true, inverse:null}) anotherModel;
I want to validate, as part of my Joi schema for aModel
, that anotherModel
has been selected.
The problem is that ember automatically fills the field with a Proxy(PromiseBelongsTo)
so within the Joi schema, if I simply have
anotherModel: Joi.any().required()
Joi considers it fulfilled despite the actual proxy object being empty.
I have tried defining the field as Joi.object({ someFields . . .})
but additionally, when the object is set by the client, the validation for the field does not detect the change and re-validate the field.
Is there a generally accepted way to specify that anotherModel
is a proxy/object? is this possible at all in the given context?
edit for clarification:
I do not care what the fields of anotherModel
contain, I don't need to validate its values. I only care that aModel
has anotherModel
within its anotherModel
field
ember 5.12
Joi 17.13.3
my emberjs model aModel
has a field which is defined like this:
@belongsTo('anotherModel', {async:true, inverse:null}) anotherModel;
I want to validate, as part of my Joi schema for aModel
, that anotherModel
has been selected.
The problem is that ember automatically fills the field with a Proxy(PromiseBelongsTo)
so within the Joi schema, if I simply have
anotherModel: Joi.any().required()
Joi considers it fulfilled despite the actual proxy object being empty.
I have tried defining the field as Joi.object({ someFields . . .})
but additionally, when the object is set by the client, the validation for the field does not detect the change and re-validate the field.
Is there a generally accepted way to specify that anotherModel
is a proxy/object? is this possible at all in the given context?
edit for clarification:
I do not care what the fields of anotherModel
contain, I don't need to validate its values. I only care that aModel
has anotherModel
within its anotherModel
field
1 Answer
Reset to default 0I really don't like this solution, but I added a field on the model: @attr() anotherModelSelected;
and in the function that is setting anotherModel
also set anotherModelSelected
to true (and false when cleared). Then in the schema definition, ignored anotherModel
and tracked anotherModelSelected
instead.
I don't like it because it adds another field to the model when the actual field we WANT to test is already present in the model, but I'll roll with this for now...