-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a way to reuse the const in some query conditions. #37
Comments
I am using the const strategy and have the following config set:
When I save an entity by allowing a user to select from a select list using the helper $this->set('priorities', $this->Articles->enum('priority')); this plugin would save MASS_PARTICIPATION_EVENT. This is ok, but it then makes it very hard to achieve the following: 1/ Query all records with a internal_type of MASS_PARTICIPATION_EVENT Previously I would do something like OccasionTypes::OCCASION_TYPE_MASS_PARTICIPATION_EVENT, but this will not work (as this would reference "mass_participation_event" (what I have previously been saving) . I would still like to use OccasionTypes::OCCASION_TYPE_MASS_PARTICIPATION_EVENT, but maybe if this plugin could provide a method which returns the actual value it will use. I hope this use case is clear |
Use |
Thanks @ADmad this works to some extent. I still have to disable the applicationRules to get it to save though. Is the idea that the value of the constant should be the label to display in select lists etc...? |
It should work with application rules enabled too. Do some digging and find out what's the problem. |
@ADmad I did some testing. I was saving multiple entities in a single transaction. Some of these had a a "null" for the enum value. I can see you already made a PR to allowEmpty. That did the trick. I still don't feel I am using the const strategy correctly though. OCCASION_TYPE_MASS_PARTICIPATION_EVENT = "mass_participation_event" Presumably the "mass_participation_event" is just a display label that I am now effectlivley using as the const value (when using this in a find query or manually setting the value of internal_type in any beforeSave etc... Thanks |
Hey @birdy247, I'll be starting to work on it today. @ADmad we have this problem, lowercase and and disable the applicationRules won't solve that problem. For example if you a const: const OCCASION_TYPE_MASS_PARTICIPATION_EVENT = "Just a test"; and we are using lowercase, I'll save "mass_participation_event" and we won't able to find it in the database because we have other text. |
Hi @pmoraes Is there a branch for this fix? I am happy to help with the development. Presumably, we just need a simple "lookup" function whereby you pass the constant and it returns the value that would normally be saved to the DB/added as the value in select lists? |
Currently we don't have this feature implemented. For now we need to take the list and use array_search to find the value to add in the conditions.
TODO: Create a way to reuse the const to create the query conditions.
The text was updated successfully, but these errors were encountered: