Reputation: 2968
I use TranslateBehavior
with two fields:
I drop these fields from Model, because content for fields will be saved in i18n table
. It works perfectly, but sometimes in my app I use $this->Model->hasField('name')
and after when I drop fields from Model table, this function always returns false. Is there some solution?
Upvotes: 1
Views: 268
Reputation: 66170
The translate behavior uses virtual fields, as such if you query for hasField
for a field that does not exist - it will rightly return false, because the field does not physically exist.
The translate behavior creates virtual field definitions on demand before a query, and destroys them after a query. as such you can't just use the second parameter of hasField as unless you manage to call it inbetween the beforeFind and afterFind methods of the translate behavior the result will always be false:
$willAlwaysBeFalse = $this->hasField('name', true);
There are a few things you can do take your pick:
hasField
does permit you to get a positive responsehasField
always returns trueThe Simplest solution is to not delete the field. This will also ensure that, while the data may be blank, your models still work if the translate behavior is disabled or some kind of error exists.
Upvotes: 2