[Dbix-class] Time-based Relatiosnhips
Dave Cross
dave at dave.org.uk
Wed Nov 9 13:11:12 GMT 2011
I think I'm missing something obvious here. But I've fried my brain
thinking about it.
A foo can have many associated bars. So I have this.
__PACKAGE__->has_many(
'bars' => 'MyDB::Result::Bar',
{ 'foreign.foo_id' => 'self.id' },
);
But, each bar has start and end dates associated with it. So at most
one bar record is active for a foo at any given time[1].
I thought I could do something like this:
__PACKAGE__->might_have(
'active_bar' => 'MyDB::Result::Bar',
{
'foreign.foo_id' => 'self.id',
'foreign.start' => { '<=' => \'now()' },
'foreign.end => { '>=' => \'now()' }
},
);
But I get an error saying 'Invalid rel cond val'. This comes from code
in DBIx::Class::ResultSource::_resolve_condition which checks that all
values in the condition hash include the string 'self'.
So how do I model this relationship? Am I mad for even trying?
Dave...
[1] Yes, this is hard to maintain. But the schema isn't going to change.
More information about the DBIx-Class
mailing list