akeeba / fof

Rapid Application Development framework for Joomla!™ 3 and 4
0 stars 0 forks source link

Field Model not filter 0 int #655

Closed go-source closed 7 years ago

go-source commented 7 years ago

I am using Model Field and it does not filter on zero integer:

0 does not filter 1 filter correctly, field working perfect type column is tinyint(1) Please confirm if this is expected (not filter on zero int) or if this is an issue. Should I write a note in wiki to let others avoid using filters on zeros? Workaround: I changed my code to use 1 and 2 rather than 0 and 1, working ok
Eighke commented 7 years ago

0 is consider as empty for PHP, so it is expected.

You can use EmptyNonZero behaviour if needed (but it will apply the behaviour on the whole model).

nikosdion commented 7 years ago

Exactly that. It's the intended default behaviour. You should only use 0/1 in tinyint fields when they are flags (on/off). Then you should use the Boolean field type to display them, NOT the Model field.

The Model field has a very different reason of existence. It's there to manage one-to-one or one-to-many relation field, i.e. foreign keys. For instance, if my Item has a field for a Category ID it makes sense to use a Model field to display the category name instead of its numeric ID but use the category ID on save. That's what the Model field does.

Since the intended use of the fields is already noted in the Wiki there is no need to add or change anything there. This was a simple case of using the wrong tool for the task at hand. It happens :)