Using contant value as inheritance discriminator

0 votes
asked Apr 13, 2017 in Feature Request by mbartok (220 points)

It is not a big deal, but I used to define constants and used them to define discriminator in ORM mapping of inheritance discriminator map.

/**
 * @ORM\Entity(repositoryClass="RecordRepository")
 * @ORM\Table(name="record")
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="discr", type="string")
 * @ORM\DiscriminatorMap({
 *     Record::RECORD_TYPE_OFFER:"Offer",
 *     Record::RECORD_TYPE_ORDER:"Order",
 *     Record::RECORD_TYPE_INVOICE:"Invoice"
 * })
 * @ORM\HasLifecycleCallbacks
 */
abstract class Record implements Commentable, Editable, Deletable, DetailPath, Loggable
{
    use LoggedEntity, CommentedEntity;

    const RECORD_TYPE_INVOICE = 'INVOICE';
    const RECORD_TYPE_OFFER = 'OFFER';
    const RECORD_TYPE_ORDER = 'ORDER';

Skipper changes those constants after export to strings. It would be nice, if skipper detects these constant by having two colons in name and not putting those quotes in annotation.

1 Answer

0 votes
answered Apr 13, 2017 by ludek.vodicka Skipper developer (140,450 points)

Thanks for the suggestion.

I'm not sure if we can use :: as 100% rule for not putting the string into quotation marks.

Maybe this can be done in a combination of some global settings which turned such option on. I'm afraid to not broke existing models if someone is using :: in strings.

commented Apr 13, 2017 by mbartok (220 points)

I agree. As I said - it is not a big deal, I replaced my constants to strings and it works, but the purpose for those constants is to have the discriminator name defined once.

commented Apr 13, 2017 by ludek.vodicka Skipper developer (140,450 points)

I completely understand your motivation and agree that constants would be nice.

...