fuel / orm

Fuel PHP Framework - Fuel v1.x ORM
http://fuelphp.com/docs/packages/orm/intro.html
152 stars 96 forks source link

Insert only for specified columns #31

Closed WanWizard closed 13 years ago

WanWizard commented 13 years ago

Currently, Model::create() generates an insert for all defined columns, whether they are assigned a value or not.

This means that you'll get an error on columns defined as 'NOT NULL' when no value is set, even though the database has a default value defined.

huglester commented 13 years ago

Commented to receive updates on this feature

jschreuder commented 13 years ago

Actually, this relates to my comment to this commit: https://github.com/fuel/orm/commit/de3724eacf56a58a7641940462bce7d8f09a19c7

Default values should be set in the model's $_properties static variable, not by the DB for the reasons I gave there.

WanWizard commented 13 years ago

I think the docs needs more info on $_properties, and need to include a note not to use DB defaults, because this is going to confuse people.

jschreuder commented 13 years ago

Yeah, I know, I need to write more docs...

JanBoehme commented 13 years ago

hi, could you give me a hint for the syntax to define a default value via the $_properties variable?

i tried using something like 'manual_check' => '0' in the properties array which seems to work. but when i try do do a select like Model_Project::find($id_project) on that model, the system tries to select a table field named '0' which, of cause, doesn't exist.

any help would be really appreciated.

jschreuder commented 13 years ago
 class Model_Example extends Orm\Model {
    protected static $_properties = array(
        'prop' => array(
           'default' => 'value'
         ),
    );
}

And next time: use the forums, that's where questions should go.

JanBoehme commented 13 years ago

thanks! unfortunately still no luck. i started a new topic on this at http://fuelphp.com/forums/topics/view/2903