NULL values from dropdown fields
Posted: Wed Nov 13, 2013 7:17 am
Hi,
I have a project with a database with a lot of foreign keys built in from before. Most of these are made to connect tables but allow for NULL choices. Simple example below:
I then create a form that shows the table 'test' and include a dropdown field for the field 'for_id' where I can choose items from the table 'for_test'. But since I can only get nuBuilder to return a '' value for the dropdown fields the foreign key will always stop the update event (insert of the unique id works fine since then the database default NULL is used).
I look at two different solutions right now:
1. adding a post in each foreign keyed table with id being ''. Should work, but does not look like a reliable solution. If someone removes it the application will crash and the post cannot be put back using nuBuilder.
2. trying to make nuBuilder pass a NULL value for dropdown fields. Any idea how I should try that?
John
I have a project with a database with a lot of foreign keys built in from before. Most of these are made to connect tables but allow for NULL choices. Simple example below:
Code: Select all
USE `mydb`;
CREATE TABLE IF NOT EXISTS `mydb`.`for_test` (
`id` VARCHAR(15) NOT NULL ,
`text` VARCHAR(255) NULL DEFAULT NULL ,
PRIMARY KEY (`id`) )
ENGINE = InnoDB
CREATE TABLE IF NOT EXISTS `mydb`.`test` (
`id` VARCHAR(15) NOT NULL ,
`for_id` VARCHAR(15) NULL DEFAULT NULL ,
`text` VARCHAR(255) NULL
PRIMARY KEY (`id`) ,
INDEX `fk_test_1` (`for_id` ASC) ,
CONSTRAINT `fk_test_1`
FOREIGN KEY (`for_id` )
REFERENCES `mydb`.`for_test` (`id` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
I look at two different solutions right now:
1. adding a post in each foreign keyed table with id being ''. Should work, but does not look like a reliable solution. If someone removes it the application will crash and the post cannot be put back using nuBuilder.
2. trying to make nuBuilder pass a NULL value for dropdown fields. Any idea how I should try that?
John