mysql 选着大于零的_mysql – DBIx :: Class:仅选择has_many大于零的结果

在我们的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',

}

);

对于相关的数据库列:

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)

这似乎是一个明显的用例,我确信有一个简单的方法可以做到这一点,但我找不到它.

解决方法:

my $with_campaigns_rs =

$schema->resultset('ThirdPartyCampaigns')

->search_related('third_party_account');

标签:dbix-class,mysql,perl,orm

来源: https://codeday.me/bug/20190902/1791759.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值