Validation for boolean on has_many relation

I’ve 2 models :
model_A hasMany model_B on model_B I’ve an attribute called default_element (true/false)
how can I guarantee that I only have one and at most one on the connected elements with attribute=true and other false?
Thanks

…should I refer to a custom validator ? Any example ? Tnx

Hi @paskuale,

Check this section of the guide:

Guide > ActiveRecord > Dynamic Relational Query

https://www.yiiframework.com/doc/guide/2.0/en/db-active-record#dynamic-relational-query

[EDIT]
I’m sorry. I’ve failed to understand your question. The answer above is irrelevant to the issue.

I’ve no idea at the moment.

no problem we would miss, thanks anyway :wink: