SidusEAVModelBundle icon indicating copy to clipboard operation
SidusEAVModelBundle copied to clipboard

how to use EAV model with normal entity?

Open videni opened this issue 4 years ago • 1 comments

I am using EAV with normal entities.

Use case

user has many roles, roles can belong to many users. Let's assume User is an EAV model, but Role is a normal entity.

Question 1 : how to design the User EAV model.

sidus_eav_model:
    families:
        Project:
            attributeAsLabel: username
            attributes:
                username:
                    required: true
                    type: string
               roles:
                    type: integer
                    collection: true
<entity name="Acme\Component\User\Model\Role" table="acme_role">
        <id name="id" type="integer">
            <generator strategy="AUTO"/>
        </id>
        <field name="role" type="string" unique="true" length="30" nullable="false"/>
        <field name="label" type="string" length="30"/>
        <field name="description" type="text" nullable="true"/>
    </entity>

Question 2: What is the effecient way to get a list of users with associated roles?

videni avatar Jun 25 '20 05:06 videni

Hello, I think what you're looking for is already in the doc:

How to create a custom relationship with a separate Doctrine entity: https://vincentchalnot.github.io/SidusEAVModelBundle/Documentation/11-extend.html#custom-relations

How to query the model: https://vincentchalnot.github.io/SidusEAVModelBundle/Documentation/07.1-query.html

I hope this answer your questions.

VincentChalnot avatar Jul 02 '20 13:07 VincentChalnot