不要怂,就是干,撸起袖子干!

Commit 7579d2a2 by Sushant Committed by Jan Aagaard Meier

hasOne now prefer for options.as foreign key name (#5926)

* hasOne now prefer options.as for foreign key name

Conflicts:
	changelog.md

* (test) hasOne now prefer as
1 parent b7f5b84e
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
- [REMOVED] Default transaction isolation level [#5094](https://github.com/sequelize/sequelize/issues/5094) - [REMOVED] Default transaction isolation level [#5094](https://github.com/sequelize/sequelize/issues/5094)
- [ADDED] Add logging for mysql warnings, observant of the `showWarnings` option. [#5900](https://github.com/sequelize/sequelize/issues/5900) - [ADDED] Add logging for mysql warnings, observant of the `showWarnings` option. [#5900](https://github.com/sequelize/sequelize/issues/5900)
- [REMOVED] MariaDB dialect - [REMOVED] MariaDB dialect
- [FIXED] `hasOne` now prefer aliases to construct foreign key [#5247](https://github.com/sequelize/sequelize/issues/5247)
## BC breaks: ## BC breaks:
- `hookValidate` removed in favor of `validate` with `hooks: true | false`. `validate` returns a promise which is rejected if validation fails - `hookValidate` removed in favor of `validate` with `hooks: true | false`. `validate` returns a promise which is rejected if validation fails
...@@ -23,6 +24,7 @@ ...@@ -23,6 +24,7 @@
- Removed support for `pool:false`, if you still want to use single connection set `pool.max` to `1` - Removed support for `pool:false`, if you still want to use single connection set `pool.max` to `1`
- Removed default `REPEATABLE_READ` transaction isolation, use config option to explicitly set it - Removed default `REPEATABLE_READ` transaction isolation, use config option to explicitly set it
- Removed MariaDB dialect - this was just a thin wrapper around MySQL, so using `dialect: 'mysql'` instead should work with no further changes - Removed MariaDB dialect - this was just a thin wrapper around MySQL, so using `dialect: 'mysql'` instead should work with no further changes
- `hasOne` now prefer `as` option to generate foreign key name, otherwise it defaults to source model name
# 3.23.2 # 3.23.2
- [FIXED] Type validation now works with non-strings due to updated validator@5.0.0 [#5861](https://github.com/sequelize/sequelize/pull/5861) - [FIXED] Type validation now works with non-strings due to updated validator@5.0.0 [#5861](https://github.com/sequelize/sequelize/pull/5861)
......
...@@ -47,7 +47,7 @@ var HasOne = function(srcModel, targetModel, options) { ...@@ -47,7 +47,7 @@ var HasOne = function(srcModel, targetModel, options) {
if (!this.foreignKey) { if (!this.foreignKey) {
this.foreignKey = Utils.camelizeIf( this.foreignKey = Utils.camelizeIf(
[ [
Utils.underscoredIf(Utils.singularize(this.source.name), this.target.options.underscored), Utils.underscoredIf(Utils.singularize(this.options.as || this.source.name), this.target.options.underscored),
this.source.primaryKeyAttribute this.source.primaryKeyAttribute
].join('_'), ].join('_'),
!this.source.options.underscored !this.source.options.underscored
......
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../../lib/data-types')
, current = Support.sequelize;
describe(Support.getTestDialectTeaser('hasOne'), function() {
it('properly use the `as` key to generate foreign key name', function(){
var User = current.define('User', { username: DataTypes.STRING })
, Task = current.define('Task', { title: DataTypes.STRING });
User.hasOne(Task);
expect(Task.attributes.UserId).not.to.be.empty;
User.hasOne(Task, {as : 'Shabda'});
expect(Task.attributes.ShabdaId).not.to.be.empty;
});
});
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!