Answer the question
In order to leave comments, you need to log in
EAV alternative?
I just came up with an idea, and immediately decided to offer it for criticism here, let's
take a classic example with products and their parameters
, let's say it suits us that there will be up to 15 parameters specific to the product type.
what if we create 15 extra1, extra2, ... extra15 fields in the table
and already in the business logic to implement the consistency of the fields of the database to the properties of the object.
public function getProducts() {
$items = query ( ..... );
foreach($items as $item) {
switch($item->type) {
case "tv":
$product = new Product();
$product->matrix = $item['extra1'];
$product->remoteControl = $item['extra2'];
.................
break;
case "dvd":
$product = new Product();
$product->format = $item['extra1'];
$product->voltage = $item['extra2'];
.................
break;
}
}
}
Answer the question
In order to leave comments, you need to log in
this is a crutch, and not an alternative, for a long time in normal DBMS, like PostgreSQL, there are data types like an array and a hash table
This is quite a normal approach. I met this (param1, param2) even in large enterprise solutions, because it is not always possible to effectively execute an alter table to add a field, and (or) your case, when there is a set of attributes that are characteristic of a part of entities and do not intersect.
Only mapping for each entity I would take out separately:
var productToExtraMap = {
'tv' : {
matrix : 'extra_1',
remoteControl : 'extra_2'
},
'dvd' : {
...
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question