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?