[Dbix-class] (relatively) complex WHERE: how to do?
Jess Robinson
castaway at desert-island.me.uk
Thu Feb 28 12:59:54 GMT 2008
On Thu, 28 Feb 2008, Alex Povolotsky wrote:
> Hello!
>
> I have a table of allowed IP addresses, table of physical servers and table
> of virtual servers (jails).
>
> Selection of allowed-and-unused IPs looks like
>
> select * from our_ips where ipid not in (select ipid from server) and ipid
> not in (select ipid from jail);
>
> What's the best way to do it with DBIx::Class?
>
By moving it into a join instead?
I assume you have a has_many or has_one rel from "our_ips" to "server", so
does this do the same?
select * from our_ips me left join server server on me.ipid = server.ipid
where server.ipid is NULL
?
If so, make a has_* rel that forces left_join, and just have:
{ 'server.ipid' => undef }
in the where condition. Ditto for the other table.
Jess
More information about the DBIx-Class
mailing list