Injecting relationships in DBIx::Class
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?
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.
精彩评论