--- Devin Austin <[EMAIL PROTECTED]> wrote:
> worked for me, if that counts for anything. Didn't
> think of using that kind
> of logic, straight up, but clever :-)
>
> On 11/2/06, Lee Standen <[EMAIL PROTECTED]> wrote:
> >
> > It's all good :P
> > I'm often good at trying to work out what people
> mean :)
> >
> > We'll soon know if I was right, when the OP
> replies :)
Okay,
Turns out that:
select => [ 'album_id', 'user_id', \'count(image_id)
as image_id',]
was the correct select parameter to use. That gave me
the correct SQL and expected results. However I also
found that:
select => [ 'album_id', 'user_id', 'count(image_id) as
image_id',]
also worked, although I am certain that's not the
canonical way to do it.
As far as all the posts generated regarding 'as' and
potentially renaming it, well I'm sorry I didn't spot
that line in the docs, I was looking at the cookbook
examples when I was doing this so I didn't go to the
general resultset docs. However I generally support
the idea to change the name since this is the kind of
thing easy to forget if you don't use it all the time.
Larry Wall said something once about things that are
different should look different to make it intuitive
when you are trending on unfamiliar ground.
Just one thing that I'm wondering about, if anyone
knows, why do we have the:
select => [ {count=>'something'},]
when it seems like:
select => [ \'count(something)',]
does exactly the same thing. Is the first somehow
better optimised? If so it seems to me that we should
have something better than:
select => [ \'count(something) as something_else',]
But anyway it works, and thanks to all the
suggestions.
--john
> >
> >
> > Devin Austin wrote:
> > > Ah good thinking lee. Didn't mean to detract
> from the original message,
> > > i was just a bit confused.
> > >
> > > On 11/2/06, *Lee Standen* < [EMAIL PROTECTED]
> > > <mailto:[EMAIL PROTECTED]>> wrote:
> > >
> > > You can't use count() without group by in
> this example. (Unless I'm
> > > mistaken).
> > >
> > > From what I'm seeing here, it sounds like
> what you really want is:
> > >
> > > my $user =
> $schema->resultset('User')->search( username =>
> > $username,
> > > $password => $password )->count();
> > >
> > > Although I don't know why you just don't do:
> > >
> > > my $user = $schema->resultset('User')->find(
> username => $u );
> > > if ($user->password eq
> $q->param('password')) {
> > > ...
> > > }
> > >
> > > That gives the added advantage of being able
> to get other
> > information
> > > about the user as well.
> > >
> > >
> > >
> > >
> > >
> > > Devin Austin wrote:
> > > > so if i'm understanding this correctly,
> the following code:
> > > >
> > > > my $user =
> $schema->resultset('User')->single(
> > > > {
> > > > username =>
> $q->param('username'),
> > > > password =>
> $q->param('password')
> > > > },
> > > > {
> > > > select => [
> > > > \'userid, COUNT(*) as
> is_authorized',
> > > > ],
> > > > }
> > > > );
> > > >
> > > >
> > > > should produce "SELECT userid, COUNT(*)
> as is_authorized FROM
> > user
> > > > WHERE username=? and password=?".
> Correct?
> > > >
> > > >
> > > > On 11/2/06, *Brandon Black*
> <[EMAIL PROTECTED]
> > > <mailto:[EMAIL PROTECTED]>
> > > > <mailto:[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>>> wrote:
> > > >
> > > > On 11/2/06, John Napiorkowski <
> [EMAIL PROTECTED]
> > > <mailto:[EMAIL PROTECTED]>
> > > > <mailto:[EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>>> wrote:
> > > > > Hi,
> > > > >
> > > > > Not sure if I am doing this
> correctly. I am trying to
> > > > > order a result by the count of
> something but the 'as'
> > > > > parameter doesn't seem to do what
> I think it should
> > > > > do:
> > > >
> > > > [...]
> > > >
> > > > > Can anyone spot what I am doing
> wrong here?
> > > >
> > > > From:
> > > >
> > >
> >
>
http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/ResultSet.pm#as
> :
> > > >
> > > > Please note: This will NOT insert an
> AS employee_count into
> > > the SQL
> > > > statement produced, it is used for
> internal access only. Thus
> > > > attempting to use the accessor in an
> order_by clause or
> > > similar will
> > > > fail miserably.
> > > >
> > > > To get around this limitation, you
> can supply literal SQL to
> > > your
> > > > select attibute that contains the AS
> alias text, eg:
> > > >
> > > > select => [\'myfield AS alias']
> > > >
> > > > -- Brandon
> > > >
> > > >
> _______________________________________________
> > > > List:
> > >
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> > > > Wiki:
> http://dbix-class.shadowcatsystems.co.uk/
> > > >
> <http://dbix-class.shadowcatsystems.co.uk/>
> > > > IRC: irc.perl.org#dbix-class
> > > > SVN:
> >
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> > > > Searchable Archive:
> > > >
>
http://www.mail-archive.com/[email protected]/
> > > >
> > > >
> > > >
> > > >
> > > > --
> > > > timorperfectus.com
> <http://timorperfectus.com>
> > > <http://timorperfectus.com
> <http://timorperfectus.com>> - web design
> > to
> > > > frightening perfection.
> > > >
> > > >
> > > > One last song
> > > > Given to an Angel's Son
> > > > As soon as you were gone
> > > > As soon as you were gone
> > > >
> > > >
> > > >
> > >
> >
>
------------------------------------------------------------------------
> > >
> > > >
> > > >
> _______________________________________________
> > > > List:
> >
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> > > > Wiki:
> http://dbix-class.shadowcatsystems.co.uk/
> > > > IRC: irc.perl.org#dbix-class
> > > > SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> > >
>
<http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/>
> > > > Searchable Archive:
> > >
>
http://www.mail-archive.com/[email protected]/
> > >
> > >
> _______________________________________________
> > > List:
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> > > Wiki:
> http://dbix-class.shadowcatsystems.co.uk/
> > > <http://dbix-class.shadowcatsystems.co.uk/>
> > > IRC: irc.perl.org#dbix-class
> > > SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> > > Searchable Archive:
> > >
>
http://www.mail-archive.com/[email protected]/
> > >
> > >
> > >
> > >
> > > --
> > > timorperfectus.com <http://timorperfectus.com> -
> web design to
> > > frightening perfection.
> > >
> > >
> > > One last song
> > > Given to an Angel's Son
> > > As soon as you were gone
> > > As soon as you were gone
> > >
> > >
> > >
>
------------------------------------------------------------------------
> > >
> > > _______________________________________________
> > > List:
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> > > Wiki: http://dbix-class.shadowcatsystems.co.uk/
> > > IRC: irc.perl.org#dbix-class
> > > SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> > > Searchable Archive:
> >
>
http://www.mail-archive.com/[email protected]/
> >
> > _______________________________________________
> > List:
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> > Wiki: http://dbix-class.shadowcatsystems.co.uk/
> > IRC: irc.perl.org#dbix-class
> > SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> > Searchable Archive:
> >
>
http://www.mail-archive.com/[email protected]/
> >
>
>
>
> --
> timorperfectus.com - web design to frightening
> perfection.
>
>
> One last song
> Given to an Angel's Son
> As soon as you were gone
> As soon as you were gone
> > _______________________________________________
> List:
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
http://www.mail-archive.com/[email protected]/
__________________________________________________________________________________________
Check out the New Yahoo! Mail - Fire up a more powerful email and get things
done faster.
(http://advision.webevents.yahoo.com/mailbeta)
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/