Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

NULL values from dropdown fields

Post Reply
johnbertell
Posts: 14
Joined: Thu Oct 24, 2013 6:32 am

NULL values from dropdown fields

Unread post by johnbertell »

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:

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 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
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: NULL values from dropdown fields

Unread post by admin »

John,

nuBuilder will only try to update fields that have been edited. This allows two parties to update different parts of a record without one over writing the other's changes.
You may have to force it to think each field has been edited using uDB http://wiki.nubuilder.com/tiki-index.ph ... _pElement_
Otherwise you could remove FOREIGN KEY CONSTRAINTS.

This might help.

Steven
d_dev
Posts: 1
Joined: Mon Nov 18, 2013 5:57 pm

Re: NULL values from dropdown fields

Unread post by d_dev »

Hi all,

first of all, NuBuilder is really good and i can imagine developing is really hard work. You have my respect. Steven, do you think that it is a good idea to remove ALL foreign key constraints? What if you have on whole db system too many tables and around 100 foreign keys? The purpose of the foreign key is to ensure consistency of data directly within the source (independent on application layer).

The same problem with NULL value is with LOOK UP field. When no change is made on the look up field and the record is saved afterwards, the Nubuilder is trying put the empty string value (not NULL) into the db. Is there really no easy way how to natively force the NuBuilder to save a NULL value into the database, in case that the field is empty?

Steven, you said, that the possibility is to use uDB. Can you provide us with a small example concerning NULL value? :?:

Many thanks and good luck to you and your team.

David
Post Reply