views:

182

answers:

0

In the application I am building, users can specify relationships between tables.

Since I only determine this at runtime, I can't specify has_many or belongs_to relationships in the schema modules for startup.

So given two tables; system and place, I would like to add the relationship to join records between them.

I have part of the solution below:

$rs = $c->model('DB::system')->result_source;
$rs->add_relationship('locations','DB::place',{'foreign.fk0' => 'self.id'});

So the column fk0 would be the foreign key mapping to the location primary key id.

I know there must be a re-registration to allow future access to the relationship but I can't figure it out.