Skip to content

change(model): new options.underscored implementation#9304

Merged
sushantdhiman merged 7 commits into
masterfrom
underscored
Apr 18, 2018
Merged

change(model): new options.underscored implementation#9304
sushantdhiman merged 7 commits into
masterfrom
underscored

Conversation

@sushantdhiman
Copy link
Copy Markdown
Contributor

@sushantdhiman sushantdhiman commented Apr 14, 2018

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

Implements proposal from #6423 (comment)

Closes #6423
Closes #7255

@sushantdhiman sushantdhiman requested review from a team, eseliger and janmeier April 14, 2018 13:05
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2018

Codecov Report

Merging #9304 into master will increase coverage by 0.01%.
The diff coverage is 98.18%.

@eseliger
Copy link
Copy Markdown
Member

looks good so far but this is a breaking change, isn't it?

@sushantdhiman
Copy link
Copy Markdown
Contributor Author

We are under v5 beta process so we can break things

@eseliger
Copy link
Copy Markdown
Member

oh I thought it was still the v5 branch

Comment thread docs/associations.md
By default the foreign key for a belongsTo relation will be generated from the target model name and the target primary key name.

The default casing is `camelCase` however if the source model is configured with `underscored: true` the foreignKey will be `snake_case`.
The default casing is `camelCase`. If the source model is configured with `underscored: true` the foreignKey will be created with field `snake_case`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Users might not know the field terminology yet - So maybe an explainer here

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this explainer should also be moved further up - It relates to all types of associations.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There was section about foreign keys further down, I have moved that up and corrected old examples

Comment thread docs/associations.md
Project.hasMany(User, {as: 'Workers'})
```

This will add the attribute `projectId` or `project_id` to User. Instances of Project will get the accessors `getWorkers` and `setWorkers`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This will add the attribute projectId to the User model. Depending on your setting for underscored the column in the table will either be called projectId or project_id

@sushantdhiman sushantdhiman merged commit 5941bfe into master Apr 18, 2018
@sushantdhiman sushantdhiman deleted the underscored branch April 18, 2018 07:31
@abelosorio
Copy link
Copy Markdown

I'm super happy that this issue is closed! I was really anxious about this feature. Is there any idea on when (or which version) is this going to be released?

@sushantdhiman
Copy link
Copy Markdown
Contributor Author

5.0.0-beta.3 https://github.com/sequelize/sequelize/blob/master/docs/upgrade-to-v5.md#500-beta3

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants