Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions

DatObjectDecoreator SQL Query Not working


Reply

3 Posts   328 Views

Avatar
voodoochile

18 September 2012 at 8:25pm Community Member, 52 Posts

Hi

I have created a DataObjectDecorator that contains a SQLQuery it all works until i add the
HERE Statement in. the DataObjectDecorator decorate a DataObject called Quote and Quote has a Has_Many Relationship to Recipe.
I want to sum the weights in recipe where the quoteID in Recipe is the same as the Quote ID.

<?php

class ExQuote extends DataObjectDecorator {
   
function TotalWeight()
{

$sqlQuery = new SQLQuery(
    "SUM(Recipe.Weight)", // Select
    "Recipe", // From
       "Recipe.QuoteID =" . $this->Owner->ID //Where
      
       );
   
    $totalWeight = $sqlQuery->execute()->value();

return $totalWeight;

}
      public function updateCMSFields(FieldSet &$fields){
      
      
      $fields->addFieldToTab("Root.Checks", new LiteralField ( '','Total Weight'));
      $fields->addFieldToTab("Root.Checks", new LiteralField ('', $this->TotalWeight()));

   }
   
}

can anyonre help please?

Avatar
simon_w

18 September 2012 at 8:40pm Forum Moderator, 474 Posts

You want $this->owner, not $this->Owner. Properties are case sensitive.

Avatar
voodoochile

18 September 2012 at 10:07pm Community Member, 52 Posts

Hey
Thanks Simon_W, this sorted it, something for me to remember in future too