__zac__ Posted March 31, 2016 Share Posted March 31, 2016 (edited) 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 March 31, 2016 by __zac__ (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now