views:

26

answers:

2

Rails 3...

I have a controller..

class OrdersController < ApplicationController
  def index
    @os_orders = OrlandoOrder.all
    @ct_orders = ChicagoOrder.all
  end
end

And then I have the two models defined...

class ChicagoOrder < Order
  Order::ActiveRecord::Base.table_name_prefix = 'ct_schema.'
end

class OrlandoOrder < Order
  Order::ActiveRecord::Base.table_name_prefix = 'os_schema.'
end

And then the parent model...

class Order < ActiveRecord::Base

end

What I'm trying to do is have the same objects Orders in this case established across multiple database schemas...

According to the log, the sql is correct...

ChicagoOrder Load (60.7ms) SELECT ct_schema.orders.* FROM ct_schema.orders

However, instead of loading OrlandoOrder and then ChicagoOrder, it loads the first model specified TWICE. So in this case, its loading OrlandoOrder twice and running that sql statement twice and loading it into @ct_orders instead of ChicagoOrder.all.

Am I doing something natively wrong? Am I doing something rails isn't intended to do with the multiple schemas?

Please advise one way or the other, been staring at this for hours and can't seem to google the right terms to see if anyone else has shared my pain...

THANKS!!!!!!!!!

A: 

HI, This is happening because you are inherinting Order model in ChicagoOrder and OrlandoOrder. Just write ChicagoOrder and OrlandoOrder by inheriting simple active record model class.And then try it.

gsoni
The problem is that 90% of the functionality ChicagoOrder and OrlandoOrder will eventually have will be identical, so I was hoping to spawn them from a common place. I was hoping to not have to specify the same relationships over and over. Also, the actual table name is "Orders". If I use OrlandoOrder and ChicagoOrder < ActiveRecord::Base, I'll have to overwrite the table name...
Mike
A: 

kjghbkjfnbkjgnbngbngknblk

DUB