Hello

Thanks for the reply.

I think i didnt explain properly. The sample you show is for view page
of each event.

But my requirement is for the event display grid where you wont have a
event id

we get all events and display in a grid. In that grid we add one more
column "no. of registrations",
where we get the count of users registered.





On Apr 18, 10:49 pm, nurvzy <nur...@gmail.com> wrote:
> I agree with John Andersen, you should use the counterCache in this
> situation, but to answer your question -- how do you preform acount
> in CakePHP from a hasMany relationship -- you get acountlike this:
>
> //in a events_controller.php within
> function view($id){
>   $attendants_count = $this->Event->EventRegistration->find('count',
> array('conditions' => 'EventRegistration.event_id' => $id));
>   $this->set(compact('attendants_count'));}
>
> That's the easiest way to get acountof a hasMany relationship from a
> parent. However, I highly suggest using counterCache so you'll have
> thiscountdata within your parent table (events).
>
> HTH
> Nick
>
> On Apr 15, 4:05 pm, mdb <meena.d...@gmail.com> wrote:
>
>
>
>
>
> > Hello,
>
> > I have Events view.ctp where i display list of Events (Event Name ,
> > Location and Date)
>
> > In EventRegistration table i have the users registered for each event.
> > (Event id , UserId)
>
> > Now in my EventView.ctp i need to add no. of registered users for each
> > event.
>
> > the SQL query will be
>
> > Select a.EventName,a.EventLocation,a.Date,
> > (Selectcount(*) from EventRegistraion b where b.EventId = a.EventID)
> > as userscount
> >  from Events a.
>
> > How do i write the equivalent of this query in cakephp?
>
> > Please Help
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
> their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group 
> athttp://groups.google.com/group/cake-php?hl=en- Hide quoted text -
>
> - Show quoted text -

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to