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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

CurrencyField not accepting inputs in nested HasManyDataObjectManager


Go to End


2 Posts   1272 Views

Avatar
Erin

Community Member, 26 Posts

31 May 2010 at 10:24am

Edited: 31/05/2010 11:29am

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?

Avatar
Erin

Community Member, 26 Posts

31 May 2010 at 11:50am

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

Please mark as solved.