[jifty-devel] Database interface

Thomas Themel thomas at themel.com
Wed Aug 16 17:08:58 EDT 2006


Hi,
Thomas Themel (thomas at themel.com) wrote on 2006-08-15:
> However, I can't seem to figure out how to do joins on my data. I can't
> get rid of the feeling that it should be possible since there's a join
> method on the collection object, but I'm getting nowhere.

Excuse my idiocy. I have no idea how I missed it in the docs, even
though I could swear I read the join method's documentation a hundred
times. 

Just for the record, here's the code that does what I asked for 
(all in a subclass of QuestLove::Model::QuestionCollection):

sub unclaimed()
{
    my $self = shift ;
    my $alias = $self->join(alias1=>'main', column1=>'number', 
            table2=>'claims', column2=>'question',
            type=>'left');
    $self->limit(alias=>$alias, column=>'id', operator=>'is', value=>'NULL');
}

sub claimed()
{
    my $self = shift ;
    my $alias = $self->new_alias('QuestLove::Model::Claim');
    $self->join(alias1=>'main', column1=>'number', alias2=>$alias, column2=>'question');
}

sub mine()
{
    my $self = shift ;
    my $calias = $self->new_alias('QuestLove::Model::Claim');
    my $ualias = $self->new_alias('QuestLove::Model::User');
    $self->join(alias1=>'main', column1=>'number', alias2=>$calias, column2=>'question');
    $self->join(alias1=>$calias, column1=>'email', alias2=>$ualias, column2=>'email');
    $self->limit(column=>'id', alias=>$ualias, operator=>'=', value=> Jifty->web->current_user->id);
}

ciao,
-- 
[*Thomas  Themel*] Usenet is not fair. After all, who shall decide what's fair?
[extended contact] For that matter, if someone is behaving unfairly, who's going
[info provided in] to stop him? Neither you nor I, that's certain.
[*message header*]  - <http://www.cs.indiana.edu/docproject/zen/zen-1.0_6.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.bestpractical.com/pipermail/jifty-devel/attachments/20060816/0687ec30/attachment.pgp


More information about the jifty-devel mailing list