[Dbix-class] Need SQL => DBIC translator
Daniel Westermann-Clark
daniel at acceleration.net
Tue Jun 20 20:48:09 CEST 2006
On 2006-06-20 09:46:53 -0700, Aran Deltac wrote:
> SELECT COUNT(*)
> FROM lang.translations tf
> LEFT JOIN lang.translations tt
> ON (tf.customer_group_id=tt.customer_group_id AND
> tf.message_code=tt.message_code)
> WHERE tt.customer_group_id=0
> AND tf.language_code="en"
> AND tt.language_code="fr"
> AND (tt.translation=tt.message_code OR tt.translation=tf.translation);
In your table class:
# Self-join
__PACKAGE__->has_many(
tt => 'YourSchema::Translations',
{
'foreign.customer_group_id' => 'self.customer_group_id',
'foreign.message_code' => 'self.message_code',
},
);
In your code:
$schema->resultset('Translations')->count(
{
'tt.customer_group_id' => 0,
'me.language_code' => 'en',
'tt.language_code' => 'fr',
-or => [
'tt.translation' => \'= tt.message_code',
'tt.translation' => \'= me.translation',
],
},
{
join => 'tt',
},
);
Maybe? There might be a simpler way, but that's what I came up with
against a schema here.
--
Daniel Westermann-Clark
More information about the Dbix-class
mailing list