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   356 Views

Avatar
voodoochile

Community Member, 52 Posts

18 September 2012 at 8:25pm

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

Forum Moderator, 474 Posts

18 September 2012 at 8:40pm

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

Avatar
voodoochile

Community Member, 52 Posts

18 September 2012 at 10:07pm

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