Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » CurrencyField not accepting inputs in nested HasManyDataObjectManager

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 1041 Views
  • Erin
    Avatar
    Community Member
    26 Posts

    CurrencyField not accepting inputs in nested HasManyDataObjectManager Link to this post

    Hi guys,
    I'm working on a restaurant site, and the way I'm adding menu items is through nested DataObjects.

    Type Menu has_many Meals. Meal has_many ItemCategories. ItemCategory has_many Items.

    Item has 3 fields with 3 formfield-types for adding them: Name (Textfield), Description (TextareaField), Price (CurrencyField).

    When I try to add an item, I get an error no matter what I enter for the price - telling me that there's no default set for Price.

    The code I'm using is this:

    class Item extends DataObject{
       static $db = array(
          'Name' => 'Text',
          'Description' => 'HTMLText',
          'Price' => 'Currency'
       );
       static $has_one = array(
          'ItemCategories' => 'ItemCategory'
       );
       function getCMSFields_forPopup() {
          $fields = new FieldSet();
          $fields->push( new TextField( 'Name' ) );
          $fields->push( new TextareaField('Description'));
          $fields->push( new CurrencyField( 'Price' ) );
          return $fields;
       }
    }

    And the error I'm receiving is this:

    [User Error] Couldn't run query: INSERT INTO `Item` SET Created = NOW() Field 'Price' doesn't have a default value
    POST /bbd/s/admin/cms/EditForm/field/Meals/item/2/DetailForm/field/ItemCategories/item/3/DetailForm/field/Items/AddForm?ctf[Items][start]=0&ctf[Items][per_page]=10&ctf[Items][showall]=0&ctf[Items][sort]=Created&ctf[Items][sort_dir]=DESC&ctf[Items][search]=&ctf[Items][filter]=

    Line 401 in C:\******sapphire\core\model\MySQLDatabase.php
    Source

    392    }
    393    
    394    function databaseError($msg, $errorLevel = E_USER_ERROR) {
    395       // try to extract and format query
    396       if(preg_match('/Couldn\'t run query: ([^\|]*)\|\s*(.*)/', $msg, $matches)) {
    397          $formatter = new SQLFormatter();
    398          $msg = "Couldn't run query: \n" . $formatter->formatPlain($matches[1]) . "\n\n" . $matches[2];
    399       }
    400       
    401       user_error($msg, $errorLevel);
    402    }
    403 }
    404
    405 /**
    406 * A result-set from a MySQL database.
    407 * @package sapphire

    Trace

    * Couldn't run query: INSERT INTO `Item` SET Created = NOW() Field 'Price' doesn't have a default value
    Line 401 of MySQLDatabase.php

    et al...

    Can I anyone tell me what I might be doing wrong?

  • Erin
    Avatar
    Community Member
    26 Posts

    Re: CurrencyField not accepting inputs in nested HasManyDataObjectManager Link to this post

    Since this issue has nothing to do with DataObjectManager, I'm closing it out.

    Please mark as solved.

    1041 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.