Ticket #317 (closed enhancement: fixed)

Opened 12 months ago

Last modified 11 months ago

class initialization with default values

Reported by: disaster Owned by: somebody
Priority: minor Milestone: 1.1
Component: Codegen Version:
Keywords: default value Cc: vexelpanda

Description

as per http://qcu.be/content/default-values-db-definition#comment-2567 it would be nice to be able to configure if the classes fields have to be initialized with default values form database, so we always save a valid object (otherwise we could have not set some not-null values)

Attachments

default-values_initialization.patch (1.0 kB) - added by disaster 12 months ago.
default-values_initialization_null_serials.patch (0.8 kB) - added by disaster 12 months ago.
don't put meaningless default values for serial fields
default-values_initialization_splitted.patch (2.3 kB) - added by disaster 12 months ago.
too many tabs
default-values_initialization_meta_control.patch (1.3 kB) - added by disaster 12 months ago.
add default initialization to meta control (disabled by default)

Change History

Changed 12 months ago by disaster

Changed 12 months ago by VexedPanda

Probably best to offload it to a subtemplate, for readability and customization purposes.

Also, to maintain the current performance for apps that don't need this, maybe we should move the construct call as part of the non-base file, and have it commented out, similar to the way there are SAMPLE LOAD METHODS..?

That should make it dead simple for anyone that wants to use it to do so, while not impacting performance of existing apps, or apps that don't need to use defaults.

Changed 12 months ago by disaster

Ok, I have tried to make it a subtemplate, but I couldnt make it..I'll try again :-)

Changed 12 months ago by MikeHostetler

  • status changed from new to infoneeded_new

I agree with VexedPanda?, this is an awesome patch! Thanks disaster!

Changed 12 months ago by VexedPanda

  • status changed from infoneeded_new to new

I love it. If you've actually generated with this, and it initializes correctly once you uncomment the constructor, let's commit it. :)

Changed 12 months ago by VexedPanda

  • status changed from new to in_QA

Changed 12 months ago by disaster

It still has some problems: for example on my postgresql database a "serial" filed has this default value:

/**
 * Protected member variable that maps to the database PK Identity column user.id
 * @var integer intId
 */
protected $intId;
const IdDefault = 'nextval(\'user_id_seq\'::regclass)';

which creates some problems :-)

what shall I do?

Changed 12 months ago by disaster

don't put meaningless default values for serial fields

Changed 12 months ago by disaster

too many tabs

Changed 12 months ago by VexedPanda

Good catches. So with these changes, everything is working great then? :)

Changed 12 months ago by disaster

In my setup, yes.
Another nice way of using this is to initialize the class in the meta_control, so if we have, for example a field "active" boolean, and default to true, it will be checked automatically on.
I have a patch also for this, disabled by default :-)

Changed 12 months ago by disaster

add default initialization to meta control (disabled by default)

Changed 12 months ago by VexedPanda

Interesting. If we uncomment the constructor in the first patch, that acheives the same effect for the meta control, does it not?

It hadn't occurred to me that a dev would want the GUI control initialized, but not progamatically created ones, but I like it. :)

Changed 11 months ago by disaster

Yes, I think that the best way of using it is to call Inizialize after you create the metacontrol on an editpanel :-) (so you have valid values also for controls that are hidden but NOT NULL)

Changed 11 months ago by VexedPanda

Tests out ok so far, and the code looks clean. I'll commit. :)

Changed 11 months ago by VexedPanda

  • status changed from in_QA to closed
  • resolution set to fixed

(In [506]) Fixes #317 provides option for object or metacontrol initialization based on default values.

Changed 11 months ago by disaster

great!

Note: See TracTickets for help on using tickets.