On 18 November 2011 21:16, Linus Pettersson <[email protected]> wrote:
> Hi!
> I'm creating an app that will import products from several XML feeds. In the
> XML there is a category specified, like T-Shirt for instance. The problem is
> that different resellers specify the categories differently. For instance,
> what one reseller calls "T-Shirts" another may call "T-Shirt", a third
> "short sleeved shirts" and so on.
> I want to somehow map these categories to the categories I have myself. So I
> need some tips on how I should create my database.
> The idea I have is to create a "raw_categories" table which contains the
> name of the resellers category and a "category_id" which has a belongs_to
> relationship to my own "categories" table. Then when I import I simply try
> to find a raw_category which has a matching name and if there is one, pick
> it, otherwise add a new one. This new one I can then manually relate to one
> of my own categories.
>
> Do you understand how I mean, and is it a good approach? Is there a
> better/more efficient way?
> - If this is a good idea. How do I do it in Rails? Should I use something
> like this (I think I've seen something like this in the API doc):
> # products model
> has_one :category, :through => :raw_categories

I think possibly you want product belongs_to raw_category and product
belongs_to category through raw_category. It has to be that way round
because you need raw_category has_many products.
Then you need category has_many raw_categories and raw_category
belongs_to product.  You can also then say category has_many products
through raw_categories.

Are you sure you need this complexity however?  You could just have
product belongs_to category (and the reverse) and work out which one
it is when you parse the xml, by looking it up in the raw_categories
table.

Colin

Colin

> I estimate that there will be about 40k to 100k products in the database.
> Regards
> Linus
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/rubyonrails-talk/-/zGGWZr75nPMJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>



-- 
gplus.to/clanlaw

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to