Ovi*_*vid 3 mysql perl orm dbix-class
在我们的MySQL数据库中,我有一个third_party_accounts表和它has_many third_party_campaigns.但是,并非所有帐户都有广告系列.我想要做的DBIx::Class只是选择那些有一个或多个广告系列的帐户.最简单的是我发现如下:
my $third_party_account_rs = $schema->resultset('ThirdPartyAccount');
my $with_campaigns_rs = $third_party_account_rs->search(
{ third_party_account_id => \'IS NOT NULL' },
{
join => 'third_party_campaigns',
group_by => 'me.id',
}
);
Run Code Online (Sandbox Code Playgroud)
对于相关的数据库列:
mysql> select id from third_party_accounts;
+----+
| id |
+----+
| 1 |
| 2 |
| 3 |
+----+
3 rows in set (0.00 sec)
mysql> select id, third_party_account_id from third_party_campaigns;
+----+------------------------+
| id | third_party_account_id |
+----+------------------------+
| 1 | 1 |
| 2 | 2 |
| 3 | 1 |
+----+------------------------+
3 rows in set (0.00 sec)
Run Code Online (Sandbox Code Playgroud)
这似乎是一个明显的用例,我确信有一个简单的方法可以做到这一点,但我找不到它.
my $with_campaigns_rs =
$schema->resultset('ThirdPartyCampaigns')
->search_related('third_party_account');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
374 次 |
| 最近记录: |