简体   繁体   中英

I can't replicate this database model in Activerecord

I'm creating a product catalogue in Rails using data from Icecat product database. I have some problems to replicate the Category - FeatureGroup - Feature structure.

This is the schema of the database, you can ignore vocabulary and language because they are for translation.

在此处输入图像描述

And this is the xml file of every single product to use as reference

XML Sample file

In my rails app I create three models:

Category
FeatureGroup
Feature

And I add a many to many relation between Category and FeatureGroup and between FeatureGroup and Feature .

Basically I think that every category has many FeatureGroups and every FeatureGroup has many Features .

But in the XML file every feature node has this structure

<ProductFeature Localized="0" ID="150078803" Local_ID="0" Value="OLED" CategoryFeature_ID="85325" CategoryFeatureGroup_ID="26690"  ...

So basically the Feature doesn't belongs to a FeatureGroup but to CategoryFeature_ID and to CategoryFeatureGroup_ID

I assume these tables are the join table between Category and Feature and beetween Category and FeatureGroup but I cannot understand the schema. And I don't have any idea how to replicate this schema in my rails app database...

I try to import the data with a task but I have about 28410 feature for one group so I think that something is wrong.

It looks like the feature_group table is used as a join table between the category_feature_group and the vocabulary tables. If you only need the Category and Feature models it seems to me you do not need the FeatureGroup model.

A feature has many categories through category_features. The category_feature table has a feature_id and a catid. So you can connect these two tables.

If you do need the feature_group table, you can find that through your category_features table and your category_feature_group table using the category_feature_group_id in the category_features table and the feature_group_id in the category_feature_group table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM