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

Properly generate default value from yml & xml mapping #1327

Closed
wants to merge 1 commit into from
Closed

Properly generate default value from yml & xml mapping #1327

wants to merge 1 commit into from

Conversation

j0k3r
Copy link
Contributor

@j0k3r j0k3r commented Mar 10, 2015

Yaml & Xml mapping which define default value for a field aren't properly generated in the entity class by the EntityGenerator.

This is how the documentation says to define a default value in xml:

<field name="login_count" type="integer" nullable="false">
    <options>
        <option name="default">0</option>
    </options>
</field>

and in yml:

    loginCount:
      type: integer
      column: login_count
      nullable: false
      options:
        default: 0

Both generates this field mapping (aka $fieldMapping):

array(5) {
  'fieldName' =>
  string(11) "login_count"
  'type' =>
  string(7) "integer"
  'nullable' =>
  bool(false)
  'options' =>
  array(1) {
    'default' =>
    string(1) "0"
  }
  'columnName' =>
  string(11) "login_count"
}

But the EntityGenerator check the default value in the wrong place, in $fieldMapping['default'] instead of $fieldMapping['options']['default'].

This is related to :

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3608

We use Jira to track the state of pull requests and the versions they got
included in.

@@ -64,7 +64,7 @@ public function generateBookEntityFixture(array $embeddedClasses = array())
$metadata->table['uniqueConstraints']['name_uniq'] = array('columns' => array('name'));
$metadata->table['indexes']['status_idx'] = array('columns' => array('status'));
$metadata->mapField(array('fieldName' => 'name', 'type' => 'string'));
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'default' => 'published'));
$metadata->mapField(array('fieldName' => 'status', 'type' => 'string', 'options' => array('default' => 'published')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add assertions for these changes? Or was the original assertion wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the documentation, the original assertion was wrong

@Ocramius Ocramius self-assigned this Mar 16, 2015
Ocramius added a commit that referenced this pull request Mar 17, 2015
@Ocramius Ocramius closed this in 8f0b339 Mar 17, 2015
@Ocramius
Copy link
Member

Merged, thanks!

master: 8f0b339
2.4: 9dfa20d

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

Successfully merging this pull request may close these issues.

3 participants