views:

61

answers:

1

I have a handful of DBIx::Class::Core objects that model various database tables.

For some of those models (those that have a 'queue' column), I have another class inject subs (basically, to 'move' the model object along it's queue states).

I'd like to also have that class inject has_many relationships ala

class($name)->has_many('queue_history','MySchema::Result::QueueHistory',
 { 'foreign.record_id'=>'self.id' },
 { where => { type => $name }} );

but I can't seem to get the relationships to register properly (keep getting "No Such Relationship" errors - however, when calling the relationship method on the sources provides back the relationship).

Any clues as to what's wrong?

+1  A: 

After some digging around, the following works:

$class = $schema->class($name)->has_many('queue_history','MySchema::Result::QueueHistory',
 { 'foreign.record_id'=>'self.id' },
 { where => { type => $name }} );

$schema->unregister_source($name);
$schema->register_class($name,$class);

The key being the unregister/register methods in order to generate all the appropriate other methods that get added by having a new has_many relationship.

Carl