Donation: -id -currency -gross -fee -charity_id Charity: -id -name
I would like to display Charities with totals for each currency.
Therefore I would like to add the following derived property to Charity:
-totals: array( array('currency'=>'GBP','total_gross'=>102.31,'total_fee'=>23.01), array('currency'=>'USD','total_gross'=>232.51,'total_fee'=>63.39) )
Which I can do with some custom SQL as follows:
SELECT currency, SUM(gross) as total_gross, SUM(fee) as total_fee FROM tbl_donation WHERE charity_id = :id GROUP BY currency
If I wasn't concerned about currency I could create STAT relations as follows:
'total_gross'=>array(self::STAT,'Donation','charity_id', 'select'=>'SUM(gross)', ), 'total_fee'=>array(self::STAT,'Donation','charity_id', 'select'=>'SUM(fee)', )
And then eager loading would reduce the amount of queries needed when rendering a list of Charities.
So my question is:
Is it possible to use a HAS_ONE relation to return a derived model that contains the totals i.e. a model that does not have a corresponding table?