Skip to content

fix(model/init): add schema name to foreign key when generating sql s… - #9255

Merged
sushantdhiman merged 3 commits into
sequelize:masterfrom
manV:fix-9029
Apr 2, 2018
Merged

sushantdhiman merged 3 commits into
sequelize:masterfrom
manV:fix-9029

Conversation

@manV

@manV manV commented Mar 30, 2018

Copy link
Copy Markdown
Contributor

…tatements (#9029) (#2464)

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

Fixes #9029 and #2464. Using getTableName() so that schema is added to foreign key reference in generated sql statement.

@codecov

codecov Bot commented Mar 30, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #9255 into master will not change coverage.
The diff coverage is 100%.

@sushantdhiman sushantdhiman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, but a few code improvements

});

it('supports schemas when defining custom foreign key attribute #9029', function() {
const self = this,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No self, with arrow function we dont need special variable to access upper scope

return self.sequelize.dropAllSchemas().then(() => {
return self.sequelize.createSchema('archive');
}).then(() => {
return User.sync({force: true });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

User.sync / Task.sync can be replaced with this.sequelize.sync

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.

schema is set using .schema() so .sync has to be called on each model separately according to this.

Comment thread test/unit/sql/create-table.test.js Outdated
}).schema('bar');
BarProject.belongsTo(BarUser, { foreignKey: 'user_id' });
it('references right schema when adding foreign key #9029', () => {
console.log(BarProject.rawAttributes);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove console.log :)

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.

done, apologies.

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.

Postgres needs Schema Name with Table Name when defining FK Constraints

2 participants