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

Commit c0c3fadb by Mick Hansen

Merge pull request #1460 from sequelize/remove-instancevalues

remove dao.selectedValues
2 parents 6f2072ae 625e2adb
......@@ -2,6 +2,7 @@ Notice: All 1.7.x changes are present in 2.0.x aswell
# v2.0.0-dev10
#### Backwards compatability changes
- selectedValues has been removed for performance reasons, if you depend on this, please open an issue and we will help you work around it.
- foreign keys will now correctly be based on the alias of the model
- foreign keys for non-id primary keys will now be named for the foreign key, i.e. pub_name rather than pub_id - if you have non-id primary keys you should go through your associations and set the foreignKey option if relying on a incorrect _id foreign key
......
......@@ -12,8 +12,6 @@ module.exports = (function() {
this.__options = this.Model.options
this.options = options
this.hasPrimaryKeys = this.Model.options.hasPrimaryKeys
// What is selected values even used for?
this.selectedValues = options.include ? _.omit(values, options.includeNames) : values
this.__eagerlyLoadedAssociations = []
this.isNewRecord = options.isNewRecord
......
......@@ -347,12 +347,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
done()
})
it("stores the passed values in a special variable", function(done) {
var user = this.User.build({ username: 'John Wayne' })
expect(user.selectedValues).to.deep.equal({ username: 'John Wayne' })
done()
})
it("attaches getter and setter methods from attribute definition", function(done) {
var Product = this.sequelize.define('ProductWithSettersAndGetters1', {
price: {
......
......@@ -228,82 +228,6 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
it('returns the selected fields as instance.selectedValues', function(done) {
var self = this
this.User.create({
username: 'JohnXOXOXO'
}).success(function() {
self.User.find({
where: { username: 'JohnXOXOXO' },
attributes: ['username']
}).done(function(err, user) {
expect(err).not.to.be.ok
expect(_.omit(user.selectedValues, ['id'])).to.have.property('username', 'JohnXOXOXO')
done()
})
})
})
it('returns the selected fields and all fields of the included table as instance.selectedValues', function(done) {
var self = this
self.Mission = self.sequelize.define('Mission', {
title: {type: Sequelize.STRING, defaultValue: 'a mission!!'},
foo: {type: Sequelize.INTEGER, defaultValue: 2},
})
self.Mission.belongsTo(self.User)
self.User.hasMany(self.Mission)
self.Mission.sync({ force: true }).success(function() {
self.Mission.create().success(function(mission) {
self.User.create({username: 'John DOE'}).success(function(user) {
mission.setUser(user).success(function() {
self.User.find({
where: { username: 'John DOE' },
attributes: ['username'],
include: [self.Mission]
}).done(function(err, user) {
expect(err).not.to.be.ok
expect(_.omit(user.selectedValues, ['id'])).to.deep.equal({ username: 'John DOE' })
done()
})
})
})
})
})
})
it('returns the selected fields for both the base table and the included table as instance.selectedValues', function(done) {
var self = this
self.Mission = self.sequelize.define('Mission', {
title: {type: Sequelize.STRING, defaultValue: 'another mission!!'},
foo: {type: Sequelize.INTEGER, defaultValue: 4},
})
self.Mission.belongsTo(self.User)
self.User.hasMany(self.Mission)
self.Mission.sync({ force: true }).success(function() {
self.Mission.create().success(function(mission) {
self.User.create({username: 'Brain Picker'}).success(function(user) {
mission.setUser(user).success(function() {
self.User.find({
where: { username: 'Brain Picker' },
attributes: ['username'],
include: [{model: self.Mission, as: self.Mission.tableName, attributes: ['title']}]
}).success(function(user) {
expect(_.omit(user.selectedValues, ['id'])).to.deep.equal({ username: 'Brain Picker' })
expect(user.missions[0].selectedValues).to.deep.equal({ id: 1, title: 'another mission!!'})
expect(user.missions[0].foo).not.to.exist
done()
})
})
})
})
})
})
it('always honors ZERO as primary key', function(_done) {
var self = this
, permutations = [
......
......@@ -1464,8 +1464,8 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect(info.count).to.equal(2)
expect(Array.isArray(info.rows)).to.be.ok
expect(info.rows.length).to.equal(2)
expect(info.rows[0].selectedValues).to.not.have.property('username')
expect(info.rows[1].selectedValues).to.not.have.property('username')
expect(info.rows[0].dataValues).to.not.have.property('username')
expect(info.rows[1].dataValues).to.not.have.property('username')
done()
})
})
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!