Jump to:

3376 Posts in 1000 Topics by 713 members

Data Model Questions

SilverStripe Forums » Data Model Questions » DatObjectDecoreator SQL Query Not working

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 268 Views
  • voodoochile
    Avatar
    Community Member
    44 Posts

    DatObjectDecoreator SQL Query Not working Link to this post

    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?

  • simon_w
    Avatar
    Forum Moderator
    467 Posts

    Re: DatObjectDecoreator SQL Query Not working Link to this post

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

  • voodoochile
    Avatar
    Community Member
    44 Posts

    Re: DatObjectDecoreator SQL Query Not working Link to this post

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

    268 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.