Hi, I''m working on a web-store app and ran into an interesting problem. I have to maintain a very large inventory from multiple facilities. Due to database performance concerns I''ve separated the inventories of each facility into a separate table. So now I have active record models for a bunch of tables like inventory_a and inventory_b. There are times, however, when I still want to treat all these tables as one. For example, for a product search I would like to be able to call find_by_sku() and have it call that method on each inventory table model. I''m currently planning on creating an inventory_all model (that does not subclass Active Record). It would contain all the methods that I would want to call on all the inventory tables as a whole, and I would end up calling it’s methods when I want to access all inventory tables (ie InventoryAll.find_by_sku). I can''t help but think that there is something I''m missing, though. Is there a better way to do this? Cheers! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Friday 01 December 2006 10:53, Raymond O''connor wrote:> I''m working on a web-store app and ran into an interesting problem. > I have to maintain a very large inventory from multiple facilities. > Due to database performance concerns I''ve separated the inventories > of each facility into a separate table. So now I have active record > models for a bunch of tables like inventory_a and inventory_b. There > are times, however, when I still want to treat all these tables as > one.Are your concerns just that or are they backed by measurements? To me, it looks like you''re working against your DBMS, in particular when you run essentially the same query multiple times. If you insist on doing this, ActiveRecord doesn''t help much. There are, as far as I can tell, two equally unattractive ways to achieve what you''re looking for within the confines of AR: (1) Use the usual #find on each individual table and write Ruby code taht combines the results. I''d expect this to be rather slow. (2) Manually write the SQL (probably consisting of UNIONized subqueries) and execute it using #find_by_sql. First and foremost, you ought to make sure that it really gives an advantage if you partition your data. Then, if you know that you can''t avoid it, have a look what your DBMS offers to facilitate this. For instance, PostgreSQL 8.1 can use views and rules to give the impression of a single logical table where there are many [*]. That way, you keep storage details out of your Rails app. Michael [*] http://www.postgresql.org/docs/8.1/interactive/ddl-partitioning.html -- Michael Schuerig mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org http://www.schuerig.de/michael/ --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Raymond O''connor wrote:> Hi, > > I''m working on a web-store app and ran into an interesting problem. I > have to maintain a very large inventory from multiple facilities. Due > to database performance concerns I''ve separated the inventories of each > facility into a separate table. So now I have active record models for > a bunch of tables like inventory_a and inventory_b. There are times, > however, when I still want to treat all these tables as one. For > example, for a product search I would like to be able to call > find_by_sku() and have it call that method on each inventory table > model. > > I''m currently planning on creating an inventory_all model (that does not > subclass Active Record). It would contain all the methods that I would > want to call on all the inventory tables as a whole, and I would end up > calling it’s methods when I want to access all inventory tables (ie > InventoryAll.find_by_sku). I can''t help but think that there is > something I''m missing, though. Is there a better way to do this? > > Cheers! > >A database that supported partitioned tables could simplify things greatly. http://dev.mysql.com/doc/refman/5.1/en/partitioning-overview.html Not sure if MySQL 5.1 is quite production ready yet, but that sounds like it would perfectly solve your problem at the source. Jack --~--~---------~--~----~------------~-------~--~----~ 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---