Jump to content

ObjectModel and


__zac__

Recommended Posts

Hi Everybody,

 

I wrote an ObjectModel containing an unsigned int as a nullable foreign key (latest PS 1.6). This field must be null if the object has no parent. It is exposed in an admin tab. The definition of this field in $this->fields_form of the Admin Controller is the following:

[
	'type' => 'select',
	'label' => $this->l('Belongs To'),
	'name' => 'parent_id',
	'required' => true,
	'options' => [
		'query' => App\LDemandtype::all()->toArray(),
		'id' => 'id',
		'name' => 'description',
		'default' => [
		  	'label' => $this->l('None'),
		  	'value' => 0
		]
	],
],

In the ObjectModel descendant's $definition, the parent_id field is defined as:

'parent_id' => ['type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => false],

Insert and updates are automatically managed by the objectmodel/moduleadmincontroller base classes without hooks or custom methods and everything is working well. What I need is to write NULL value in the corresponding column of the DB table when the user selects the "None" option (now the code writes 0). What is the code needed to achieve my goal?

Edited by __zac__ (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...