Skip to content
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

Enums not working with irregular fieldnames #31

Closed
inoas opened this issue Feb 22, 2017 · 3 comments
Closed

Enums not working with irregular fieldnames #31

inoas opened this issue Feb 22, 2017 · 3 comments

Comments

@inoas
Copy link
Contributor

inoas commented Feb 22, 2017

Problem

    const SALUTATION_001 = 'Herr';
    const SALUTATION_002 = 'Frau';
    const SALUTATION_003 = 'Firma';
    const SALUTATION_004 = 'Herr und Frau';
    const SALUTATION_005 = 'Frau und Herr';
    const SALUTATION_006 = 'Frau und Frau';
    const SALUTATION_007 = 'Herr und Herr';
    const SALUTATION_008 = 'Eheleute';
    const SALUTATION_021 = 'Firma mit Ansprechpartner';
    //...
        $this->addBehavior('CakeDC/Enum.Enum', ['lists' => [
            'xml_kundendaten_adresse_anrede' => [
                'strategy' => 'const',
                'prefix' => 'SALUTATION',
                'field' => 'Xml_Kundendaten_Adresse_Anrede',
            ],
        ]]);

Error

Error CakeDC\Enum\Model\Behavior\Exception\MissingEnumConfigurationException

Workaround

        // Note that BOTH have to be set, else it throws exceptions once in _call()  and once in enum()
        $this->addBehavior('CakeDC/Enum.Enum', ['lists' => [
            'xml_kundendaten_adresse_anrede' => [
                'strategy' => 'const',
                'prefix' => 'SALUTATION',
                'field' => 'Xml_Kundendaten_Adresse_Anrede',
            ],
            'Xml_Kundendaten_Adresse_Anrede' => [
                'strategy' => 'const',
                'prefix' => 'SALUTATION',
                'field' => 'Xml_Kundendaten_Adresse_Anrede',
            ],
        ]]);

Question

Is there a reason the list keys are being inflected around inside the behavior?

@pmoraes
Copy link

pmoraes commented Mar 2, 2017

Hi @inoas, I'll be taking a look at this issue, as soon as possible I'll give a better status for you. Thanks.

@pmoraes
Copy link

pmoraes commented Mar 20, 2017

Hi @inoas, I was checking your code, so what you need to do is follow the cake standard, so when you set the variable from the method, you need to use camel case, you should to have something like that $this->set('xmlKundendatenAdresseAnredes', $this->YOUR_TABLE->enum('xml_kundendaten_adresse_anrede')); in your controller. You don't need to have this param 'field' => 'Xml_Kundendaten_Adresse_Anrede', do you need some help more about this question?

@inoas
Copy link
Contributor Author

inoas commented Mar 21, 2017

No I get it, however It shipped now with this code am works (tm) ;)
Next time I use CakeDC/Enum AND do not follow conventions (sorry about that, usually I do) I will try this and if it does not work will try to come up with a PR.

@inoas inoas closed this as completed Mar 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants