I would like to use one model but be able to decide which table it
accesses.
Anyone know if this is possible?
--
Posted via http://www.ruby-forum.com/.
Raul
class Foo < AbstractBase
self.table_name = 'footable'
end
class Bar < AbstractBase
self.table_name = 'bartable'
end
you may not need to set the table_name if the class names map to rails
conventions but just in case you need to do it that way.
Or;
module SharedStuff
all your common code amongst the models
end
class Foo < ActiveRecord::Base
include SharedStuff
end
class Bar < ActiveRecord::Base
include SharedStuff
end
either should achieve the same end.
James McCarthy
james2m...@gmail.com
Generating a separate model for each works best and you won't need the
self.table_name='x'. The logic and associations can still all be in the
AbstractBase.