Closed asgraf closed 4 years ago
The behavior is only for DB fetching and real fields. What you want you can easily do inside your _getName() method directly. Just return the Text::slug() value there. No need for any behaviors.
You seem to not understand my code correctly.
I have real field slug
in my userpackages table and i want to be able to to search by slug.
So i want to fill this real field slug
with a string generated from slugging contents of virtual field name
I sure don't quite fully understand the use case here. Feel free to provide a patch if you think something could be improved or fixed here.
As for non-real fields support, you could also try to extend/overwrite
public function hasField($field)
{
if ($field === 'fake') { return true; }
return parent::hasField($field);
}
in your Table class.
Just an idea.
Following code seems to solve the problem:
public function hasField($field)
{
$virtualFields = $this->newEntity()->getVirtual();
if(in_array($field, $virtualFields)) {
return true;
}
return parent::hasField($field);
}
But i still think that slug behavior should work correctly out of the box without need of overriding native cakephp methods
Can u maybe add a pr to Support this? Either by making check optional or including virtual fields?
My idea: New config key
'checkExistence' => false (default true)
for your case to not check if the field exists in model.
Actually, the existence check is mainly done to be able to get some meta data. But it has a fallback in place, and also a passing test case:
testSlugGenerationWithVirtualField()
Can you please check why this test case with a virtual field does work, but your example doesnt?
Please use latest master to check I added a better debug message for the error: https://github.com/dereuromark/cakephp-tools/commit/cde92a50ba30702c6c5d8cdd3769641d0873065a
Any update here?
I have virtual field
name
defined in in myUserpackage
entity and_getName()
getter has been implemented.Now i get following error: