You are viewing a plain text version of this content. The canonical link for it is here.
Posted to zeta-dev@incubator.apache.org by Maxime Thomas <ma...@gmail.com> on 2010/12/30 07:11:46 UTC

[zeta-dev] Persistent object vs DB Query

Hi Zetadev,

A quick question for those using ezcPersistentObject and the standard
ezcPersistentSessionINstance::createFindQuery().

I'm a bit stuck with that code :

<code>
$s = ezcPersistentSessionInstance::get();
$q = $s->createFindQuery("className");
...
$s->find($q, 'className');
</code>


How can I make distinct or count on "className" ?
Do I have to cheat and do something like this :

<code>
$db = ezcDbInstance::get();
$q = $db->createSelectQuery();
$q->selectDistinct("id");
$q->from("className");
...
$s->find($q, 'className');
</code>

Or does it have a proper way to be run ?

Or do I have to make my query with the query layer only ?

Thank you for any kind of answers.

-- 
Maxime
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou

Re: [zeta-dev] Persistent object vs DB Query

Posted by Maxime Thomas <ma...@gmail.com>.
I finally did it with a $q->groupBy() and it's working with the PO session.
The only thing I cannot do is what you've described (due to $q->select ()).
Thank you anyway for the way to correctly doing the count (I was doing like
this already but wondering if it was possible to do it with the PO session).

Regards,

Max


2011/1/3 Petar Španja <pe...@gmail.com>

> Hi Maxime,
>
> PO fetches table rows through id fields, and it makes no sense to do
> distinct on id field, ids should be unique.
> Also you can't make count query through PO session. To add this
> functionality you should add a method in the query layer to transform your
> query to count query (modify select string, remove where string etc) and a
> method in the persistent session class that will use this.
>
> Regards,
> Petar
>
> On Thu, Dec 30, 2010 at 8:11 AM, Maxime Thomas <maxime.thom@gmail.com
> >wrote:
>
> > Hi Zetadev,
> >
> > A quick question for those using ezcPersistentObject and the standard
> > ezcPersistentSessionINstance::createFindQuery().
> >
> > I'm a bit stuck with that code :
> >
> > <code>
> > $s = ezcPersistentSessionInstance::get();
> > $q = $s->createFindQuery("className");
> > ...
> > $s->find($q, 'className');
> > </code>
> >
> >
> > How can I make distinct or count on "className" ?
> > Do I have to cheat and do something like this :
> >
> > <code>
> > $db = ezcDbInstance::get();
> > $q = $db->createSelectQuery();
> > $q->selectDistinct("id");
> > $q->from("className");
> > ...
> > $s->find($q, 'className');
> > </code>
> >
> > Or does it have a proper way to be run ?
> >
> > Or do I have to make my query with the query layer only ?
> >
> > Thank you for any kind of answers.
> >
> > --
> > Maxime
> > maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou
> >
>



-- 
Maxime
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou

Re: [zeta-dev] Persistent object vs DB Query

Posted by Petar Španja <pe...@gmail.com>.
Hi Maxime,

PO fetches table rows through id fields, and it makes no sense to do
distinct on id field, ids should be unique.
Also you can't make count query through PO session. To add this
functionality you should add a method in the query layer to transform your
query to count query (modify select string, remove where string etc) and a
method in the persistent session class that will use this.

Regards,
Petar

On Thu, Dec 30, 2010 at 8:11 AM, Maxime Thomas <ma...@gmail.com>wrote:

> Hi Zetadev,
>
> A quick question for those using ezcPersistentObject and the standard
> ezcPersistentSessionINstance::createFindQuery().
>
> I'm a bit stuck with that code :
>
> <code>
> $s = ezcPersistentSessionInstance::get();
> $q = $s->createFindQuery("className");
> ...
> $s->find($q, 'className');
> </code>
>
>
> How can I make distinct or count on "className" ?
> Do I have to cheat and do something like this :
>
> <code>
> $db = ezcDbInstance::get();
> $q = $db->createSelectQuery();
> $q->selectDistinct("id");
> $q->from("className");
> ...
> $s->find($q, 'className');
> </code>
>
> Or does it have a proper way to be run ?
>
> Or do I have to make my query with the query layer only ?
>
> Thank you for any kind of answers.
>
> --
> Maxime
> maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou
>