最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ember.js - Joi validation of emberjs belongsTo - Stack Overflow

programmeradmin2浏览0评论
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

Share edited Mar 5 at 18:28 ZacMoeShop asked Mar 5 at 18:25 ZacMoeShopZacMoeShop 12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I 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...

发布评论

评论列表(0)

  1. 暂无评论