sidus/eav-model-bundle
Symfony/Doctrine bundle to build dynamic EAV models from versioned YAML config. Generate forms automatically, validate/translate/serialize easily, and contextualize attribute data across unlimited axes (language, region, channel, version, etc.). Extensible and customizable.
The canonical version of this documentation can be found here: https://vincentchalnot.github.io/SidusEAVModelBundle
This bundle allows you to quickly set up a dynamic model in a Symfony project using Doctrine.
Model configuration is done in Yaml and everything can be easily extended.
The main feature of this model that exists nowhere else to my knowledge is the possibility to contextualize data based on as many contextualization axis you need.
All EAV model allows you to contextualize data based on the language or the country (yes: internationalization is a subset of data contextualization), some models allows you to contextualize your data based on some channels or scopes but this particular implementation allows you to manage contextualization axis to conform with your business logic, not the other way around.
Main Features:
Check the Q&A section and don't hesitate to ask questions in the issues.
EAV stands for Entity-Attribute-Value
The main feature consists in storing values in a different table than the entities. Check the confusing and not-so-accurate Wikipedia article
This implementation is actually more an E(A)V model than a traditional EAV model because attributes are not stored in the database but in YAML files.
If you're not familiar with the key concepts of the EAV model, please read the following.
Performances ? Not a real issue because MySQL is not usable for searching in a vast amount of data anyway, be it an EAV model or a more standard relational model. Solution: Elastic Search: it’s currently optionally supported through the Sidus/FilterBundle with the Sidus/ElasticaFilterBundle
If you a have a complex relational model and you plan to use a lots of joins to retrieve data, it might be best to keep your relational model outside of the EAV model but both can coexists without any problem. However, there is a technical limitation when using this implementation of the EAV model: There is only one table for the Data entry and one table for the Values.
We are using Doctrine as it’s the most widely supported ORM by the Symfony community and we’re aiming at a MySQL/MariaDB implementation only for data storage.
In any EAV model there are two sides
In some implementation the model is stored in the database but here we chose to maintain the model in Symfony service configuration for several reasons:
Families and attributes are services automatically generated from your configuration, attribute types are standard Symfony services.
For a basic blog the configuration will look like this:
sidus_eav_model:
families:
Post:
attributeAsLabel: title
attributes:
title: # Default type is string
required: true
content:
type: html # This type is available through the EAVBootstrapBundle
publicationDate:
type: datetime
publicationStatus:
type: choice
form_options: # Symfony form options are passed directly
choices:
draft: Draft
published: Published
archived: Archived
author:
type: data_selector # This type allows to select an other entity inside the EAV model
options:
autoload: true # Autoload author when loading Post
allowed_families:
- Author
tags:
multiple: true
form_options:
collection_options:
sortable: true
isFeatured:
type: boolean
Author:
attributeAsLabel: name
attributes:
name:
required: true
email:
validation_rules: # Validation rules can be applied directly in the model
- Email: ~
Note that by convention we declare the families in UpperCamelCase and the attributes as lowerCamelCase and we encourage you to do so.
How can I help you explore Laravel packages today?