entity-attribute-value

Looking for a right EAV structure based on jsonb

别来无恙 提交于 2019-12-04 12:31:46
问题 I wondering what will be the right approach to build EAV on jsonb. I have Attribute -> Values tables as like in standard EAV. CREATE TABLE attribute_values ( id INTEGER, attribute_id INTEGER, value VARCHAR(255) ); CREATE TABLE attributes ( id INTEGER, name VARCHAR(255) ); Values will saved in attributes filed of Entity CREATE TABLE entity ( id INTEGER, title TEXT, attributes JSONB ); Tables Attribute created to control duplicate attributes their types and better determine what it's a

How many database table columns are too many?

岁酱吖の 提交于 2019-12-04 11:03:11
I've taken over development on a project that has a user table with over 30 columns. And the bad thing is that changes and additions to the columns keep happening. This isn't right. Should I push to have the extra fields moved into a second table as values and create a third table that stores those column names? user id email user_field id name user_value id user_field_id user_id value Do not go the key / value route. SQL isn't designed to handle it and it'll make getting actual data out of your database an exercise in self torture. (Examples: Indexes don't work well. Joins are lots of fun

How make this eav query to make horizontal result

落爺英雄遲暮 提交于 2019-12-04 10:29:05
The case: tables: product: product_id|name | ------------------------ 1 |iphone 4 | 2 |gallaxy 2 | 3 |blackbery 6 | product_attribute: id|product_id|attribute_id -------------------------------------------------- 1 |1 |2 2 |1 |6 . . . attribute: ------------------------------ attribute_id|name |value| 1 |width |300 2 |width |320 3 |width |310 4 |height|390 5 |height|370 6 |height|380 should get result: product_id|height|width 1 |380 |320 ...................... Edit: height and width attributes its only part of product attributes - product need to have dynamic ability to be added by the user in

Proper way to store user defined data in SQL

╄→гoц情女王★ 提交于 2019-12-04 05:05:28
问题 I want to build an online form builder much like wufoo that allows the users to create and publish their own web forms. Each submission should be saved to a data base where the user can later retrieve the submissions. As these forms will be dynamic, ie. the user has complete control over the amount and type of form fields I am trying to think of a solid database design to store this information. I would have one table fieldtype which contains every type of field available to the users, ie.

MySQL: how to convert to EAV?

南楼画角 提交于 2019-12-04 01:41:00
问题 Say I have the following table: TABLE: one =============================== | id | first_name | last_name | =============================== | 1 | John | Doe | | 2 | Jane | Smith | ------------------------------- I want to convert it to an EAV: TABLE: two =================================== | id | fk_id | attribute | value | =================================== | 1 | 1 | first_name | John | | 2 | 1 | last_name | Doe | | 3 | 2 | first_name | Jane | | 4 | 2 | last_name | Smith | ------------------

Design database based on EAV or XML for objects with variable features in SQL Server?

南楼画角 提交于 2019-12-03 21:09:01
I want to make a database that can store any king of objects and for each classes of objects different features. Giving some of the questions i asked on different forums the solution is http://en.wikipedia.org/wiki/Entity-attribute-value_model or http://en.wikipedia.org/wiki/Xml with some kind of validation before storage. Can you please give me an alternative to the ones above or some advantages or examples that would help decide which of the two methods is the best one in my case? Thanks UPDATE 1 : Is your db read or write intensive? will be both -> auction engine Will you ever conceivably

How to store meta-data on columns

六眼飞鱼酱① 提交于 2019-12-03 18:51:34
问题 Let's say you're collecting insider info on upcoming superhero movie releases and your main Movie table looks something like this: Table 1 Title Director Leading Male Leading Female Villain -------------------------------------------------------------------------- Green Lantern Kubrick Robert Redford Miley Cyrus Hugh Grant The Tick Mel Gibson Kevin Sorbo Linda Hunt Anthony Hopkins This should work very well in general and allow very easy queries as well as comparisons between rows. However,

Magento category ID from product ID

徘徊边缘 提交于 2019-12-03 18:04:15
问题 In magento how to get the category id of each product from its product ID. $items = $request->getAllItems(); $c = count($items); for ($i = 0; $i < $c; $i++) { if ($items[$i]->getProduct() instanceof Mage_Catalog_Model_Product) { if ($items[$i]->getProduct()->getId()) { $this->_dhlAllowed = false; } } } Here $items[$i]->getProduct()->getId() returns product ID. I want its category ID. 回答1: public function getProductCategory() { /* @var $product Mage_Catalog_Model_Product */ $product = Mage:

Magento: add new attribute to all products

爱⌒轻易说出口 提交于 2019-12-03 18:00:42
问题 I want to add a new attribute to all products. I have done it with a install script trough $installer = $this; $installer->startSetup(); $this->addAttribute('catalog_product','test2',array( 'label' => 'test2', 'type' => 'varchar', 'visible' => true, 'required' => false, 'required' => 0 )); But how can I add values to this attribute by $entityTypeId = $installer->getEntityTypeId('catalog_product'); $attributeSetId = $installer->getDefaultAttributeSetId($entityTypeId); $attributeGroupId =

Implementing EAV pattern with Hibernate for User -> Settings relationship

可紊 提交于 2019-12-03 15:02:57
I'm trying to setup a simple EAV pattern in my web app using Java/Spring MVC and Hibernate. I can't seem to figure out the magic behind the hibernate XML setup for this scenario. My database table "SETUP" has three columns: user_id (FK) setup_item setup_value The database composite key is made up of user_id | setup_item Here's the Setup.java class: public class Setup implements CommonFormElements, Serializable { private Map data = new HashMap(); private String saveAction; private Integer speciesNamingList; private User user; Logger log = LoggerFactory.getLogger(Setup.class); public String