0

I have many tables in my database which have the same structure. I want to create a common result class (package DBIx::Class) for that set of tables and use the same class for all by somehow changing the table name on the fly.

How can I do this?

EDIT Encouraged by the answer from @abraxxa I am extending the same question. In my database I have a set of tables for many customers which have common structure. After creating a common set of result classes I want to use the same for all customers in following fashion.

customer 1

tableA_1 tableB_1 tableC_1

customer N

tableA_N tableB_N tableC_N

while working on customer N, I want to manage tableA, tableB and tableC such that their relationships are also maintained. Like, if I access tableB from within tableA, then for customer 1 it should access tableB_1 and for customer N tableB_N should be accessed.

Can you please outline a base class for tableA and then one the subclass for the same.

bvnbhati
  • 382
  • 4
  • 17
  • I realize this ship may have already sailed, but if the structure is the same, why not have a schema/database per customer? Then fully qualify your schema using `__PACKAGE__->table('schema.table')` and cross-schema joins are possible (assuming hosted on the same server). Common ResultSets and Results then can be used. – mikew Jan 08 '15 at 15:01
  • @mikew I am actually uncovering the facts one by one. All these tables are in same schema and also share global tables. so tableA_1 and tableA_2 both join with global_table using same type of structure. – bvnbhati Jan 08 '15 at 16:09

1 Answers1

3

Create a Result base class and subclass it for each existing table only calling

__PACKAGE__->table('tablename');

in each subclass. DBIx::Class still needs to know about all existing tables because of their relationships.

Alexander Hartmaier
  • 2,178
  • 12
  • 21