I am trying to get count of proposals for each request that is posted in my site using statistical query.i.e, the count of proposals for each request that the logged in user has posted . I am getting the count of all users by using the code
return array(
'serviceproposals' => array(self::HAS_MANY, 'Serviceproposal', 'ServiceRequestID'),
'user' => array(self::BELONGS_TO, 'Buyer', 'user_id'),
'postCount'=>array(self::STAT, 'serviceproposal', 'ServiceRequestID'),
);
Database:
User[user_id,name,password],
Provider[user_id,providercompany,providerdetails],
Buyer[user_id,contactinfo],
ServiceRequest[ServiceRequestID,Buyer.user_id,details,date],
ServiceProposal[ServiceProposalId,ServiceRequestID,Provider.user_id,services,propsal_rate]
All suggestions are invited…
For this you need to pass the
user_idof the currently logged in user, to theSTATrelation.There are 2 ways of achieving this, use a conditional query, or using Parameterized named scopes
Conditional Query.
Eager Loading:
Lazy Loading:
Parameterized Named Scope:
In your model
Then use like:
Eager loading:
Lazy Loading: