Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating Doesn't Respect Field Defaults #12

Closed
agentphoenix opened this issue Apr 22, 2011 · 4 comments
Closed

Creating Doesn't Respect Field Defaults #12

agentphoenix opened this issue Apr 22, 2011 · 4 comments
Labels

Comments

@agentphoenix
Copy link

When you create a new record with the ORM, it doesn't respect the field defaults and puts NULL in instead. If a value isn't set in what's passed over to the save() method, the ORM shouldn't be setting it to NULL, it should be letting the table set what goes in the fields that were omitted.

@jschreuder
Copy link
Contributor

Actually that's not true, defaults should be set in the model because the model should always fully represent what's in the database. If you let your DB decide what to put in there the model wouldn't be complete after creation and you'd be working with potentially incorrect data. This is why the Orm\Model will never support DB defaults.

It's true however that the model doesn't yet support default values, that will probably be in for the 1.0 release though.

@agentphoenix
Copy link
Author

Okay, so at least I'm not going crazy. I tried throwing a default array item on some of the properties and it didn't do anything, so I just wanted to make sure it was reported so it could be fixed for 1.0. Thanks!

@jschreuder
Copy link
Contributor

To let you know: the Orm\Model now uses default values set with $_properties, below is an example:

protected static $_properties = array(
    'name' => array(
        'default' => '(none)',
    ),
);

Edit: until the next release it's only in the develop branch.

@agentphoenix
Copy link
Author

Perfect! Thanks for the quick turnaround on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants