Use default value when adding entity attribute

By Ritchie Annand on 30 Nov (4 days ago)

When you specify a default value for an entity attribute, OutSystems uses that when you make a new record and do not/fail to specify the value for that attribute.

However, when you publish your changes, the database is filled with the "blank" value instead of the default value.

To illustrate, if you add a new column called Quantity to multiply an expense by, you give it a default value of 1 so that the value comes out the same. However, the new Quantity column in the database is filled with zeroes

It's not hard to get around - you just have to make update SQL that sets all the zeroes or blanks to the default value - but it seems like it shouldn't be necessary :)

-- Ritchie Annand

Justin James1 Dec (3 days ago)

I like the idea in priciple, but without storing a "dirty bit" on every column (super inefficient!) this won't work.


Imagine this scenario:

* Default value is "bob"

* Record created, defaults to "bob"

* User edits record, sets it to "jim"

* User edits record, sets it to "bob"

* Default value changed to "john"

* Record that had the value deliberately set to "bob" by a user now get sets to "john"

See the problem? You need a flag on EACH column indicating if it was changed from its original value by application code. Even then, let's say a user brings up  record, makes no change to the default value and clicks "save"... they approve of the default values... do you change that when the default changes, or leave it be?

So fundamentally, this change is impossible to implement at a system level in a manner that actually will not destroy application data.

J.Ja

Paulo Ferreira2 Dec (2 days ago)

Justin, I read the idea as something slightly simpler, which is to just fill the default value on the first deploy that adds the column.

That's actually the behavior for Local Storage Entities in P10, if I'm not mistaken.

Justin James2 Dec (2 days ago)

Paulo -

That's not what it says. It very clearly about existing records in the database already having blank/wrong default values if you do not set it correctly first. The existing behavior for server DB is to set the value when you add the column too, so that wouldn't be the change.

J.Ja

Paulo Ferreira2 Dec (2 days ago)

Hi Justin,

I still don't read it that way, but you're right about the existing behavior. For some reason I thought it was different.

Cheers,

Paulo