Code Monkey home page Code Monkey logo

Comments (6)

pmoraes avatar pmoraes commented on July 25, 2024 1

Hi @lilHermit for this case, you'll need to create a custom strategy, because we use the const name without the prefix to put in the option value and the const value to show in the list. So we don't have any strategy to work as you want. I suggest you to create new strategy than this work around.

Let us know if you need some more help about this issue.

Thanks,
Peter Moraes.

from enum.

pmoraes avatar pmoraes commented on July 25, 2024

Hi @lilHermit, if you want to put the integer in the database you need to create the constants in this way.

const TYPE_0 = 'PLATFORM';
const TYPE_1 = 'USER';
const TYPE_2 = 'DEVICE';

it will show the list using the names and the values will be the numbers.

do you have any question yet?

from enum.

lilHermit avatar lilHermit commented on July 25, 2024

@pmoraes Yeah that doesn't help because I want the constants to be meaningful so I can use them in queries.

$query->conditions(['type' => SampleTable::TYPE_PLATFORM]);

I'll go with the hacky approach but if I need it again I might look at writing a "Strategy"

from enum.

inoas avatar inoas commented on July 25, 2024

But where is it hacky? That's how PHP constants work. We do not have atoms/symbols in PHP, sadly.

You can of course do:

    const TYPE_PLATFORM = 'TYPE_PLATFORM';
    const TYPE_USER = 'TYPE_USER';
    const TYPE_DEVICE = 'TYPE_DEVICE;

... then 'type' => SampleTable::TYPE_PLATFORM should work.

And then at some point do some po file translation, if required.

from enum.

lilHermit avatar lilHermit commented on July 25, 2024

@inoas I think disabling applicationRules and using array_flip is a bit hacky personally.

I want to have an integer in the db for query/index speed.

No problem thanks for your time.

from enum.

lilHermit avatar lilHermit commented on July 25, 2024

The solution was quite simple for integer constants

https://bitbucket.org/snippets/lilHermit/onaLe

It would be easy to add a config option to the ConstStrategy for integers, which adds this array_flip if other users request it.

Also as the validation callback uses the enum method this fixes the Application rules issue too.

from enum.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.