Comments (7)
I am using the const strategy and have the following config set:
const OCCASION_TYPE_MASS_PARTICIPATION_EVENT = "mass_participation_event";
const OCCASION_TYPE_TRAINING_SESSION = "training_session";
const OCCASION_TYPE_SOCIAL = "social";
$this->addBehavior('CakeDC/Enum.Enum', ['lists' => [
'internal_type' => [
'strategy' => 'const',
'prefix' => 'OCCASION_TYPE',
'className' => 'App\\Model\\Entity\\OccasionType',
'applicationRules' => false
]
]]);
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
2/ Manually assign the entities property with one of the constants
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
from enum.
Use 'lowercase' => true
in config and it will save mass_participation_event
in db instead of MASS_PARTICIPATION_EVENT
. 🙂
from enum.
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...?
from enum.
It should work with application rules enabled too. Do some digging and find out what's the problem.
from enum.
@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
from enum.
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.
from enum.
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?
from enum.
Related Issues (19)
- Problem with multi worded prefix in ConstStrategy. HOT 2
- ConstStrategy::enum() should cache generated lists.
- Setup packagist hook. HOT 4
- I can contribute to the docs for this. Just need to learn how to do so HOT 4
- Enum Helper HOT 4
- Enum translation HOT 4
- Missing Helper? HOT 4
- Enums not working with irregular fieldnames HOT 3
- Const Enum Type as integer HOT 6
- Add a config option to inject the enum validation into a validation object
- Improve default validation error
- CakePHP 3.6 Update HOT 2
- Deprecated Error in Table class at CakePHP3.6 HOT 1
- CakePHP 4 support HOT 1
- Error in ConstStrategy while formatig results HOT 2
- Error in ConstStrategy while formatting results HOT 1
- Error in Branch 3.next-cake5 in ConstStrategy HOT 3
- Problem modifying existing entity with enum and saving it
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enum.