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

Association.save is not a function #788

Open
SrTreze opened this issue May 12, 2017 · 1 comment
Open

Association.save is not a function #788

SrTreze opened this issue May 12, 2017 · 1 comment

Comments

@SrTreze
Copy link

SrTreze commented May 12, 2017

Hi!

Apparently, my server crashes when I try to use a setter in a hasMany relationship.

I have this:

db.models.target_contents.extendsTo('multimedia', {
	title              : { type: 'text'        , required : true },
	picDataURL : { type: 'text'        },
	duration       : { type: 'integer'   , required : true },
	type	             : { type: 'boolean' , required : true },  // False -> audio, True -> video
	uploadDate  : { type: 'date'       , time        : true , required: true },
	lyrics            : { type: 'text'        }
})

db.define('gender', {
	gender : { type: 'text' , unique: true , required: true }
})

db.models.target_contents_multimedia.hasMany('gender', db.models.genders, {}, {autoFetch: true, mergeTable: "songGender", reverse: 'songs'})
db.models.target_contents_multimedia.hasOne('owner', db.models.target_account, { required: true }, {reverse: 'content'})

And I have a route that gets me every song from a owner, and for each, I want to set a gender. For that, I do this:

router.post('/songs/:artistID/:offset', function(req, res){
	req.models.target_contents_multimedia.find({owner_target_tId: req.params.artistID, type: false}).limit(10).offset(req.params.offset).each(function(song){
		song.setGender(9, function(err){
			if (err) console.log(err)
                        else res.send("ok")
		})
	})
})

Problem is, when he gets to the setter, it throws the following error:

TypeError: Association.save is not a function
    at saveAssociation (/Users/joaomiguelrodrigues/Desktop/FCUL/ProjetoFinal/node_modules/orm/lib/Associations/Many.js:378:19)
    at Object.exports.wait (/Users/joaomiguelrodrigues/Desktop/FCUL/ProjetoFinal/node_modules/orm/lib/Hook.js:26:10)
    at saveNextAssociation (/Users/joaomiguelrodrigues/Desktop/FCUL/ProjetoFinal/node_modules/orm/lib/Associations/Many.js:423:12)
    at run (/Users/joaomiguelrodrigues/Desktop/FCUL/ProjetoFinal/node_modules/orm/lib/Associations/Many.js:427:12)
    at Object.value (/Users/joaomiguelrodrigues/Desktop/FCUL/ProjetoFinal/node_modules/orm/lib/Associations/Many.js:452:5)
    at Query._callback (/Users/joaomiguelrodrigues/Desktop/FCUL/ProjetoFinal/node_modules/orm/lib/Associations/Many.js:294:39)
    at Query.Sequence.end (/Users/joaomiguelrodrigues/Desktop/FCUL/ProjetoFinal/node_modules/mysql/lib/protocol/sequences/Sequence.js:86:24)
    at Query._handleFinalResultPacket (/Users/joaomiguelrodrigues/Desktop/FCUL/ProjetoFinal/node_modules/mysql/lib/protocol/sequences/Query.js:137:8)
    at Query.OkPacket (/Users/joaomiguelrodrigues/Desktop/FCUL/ProjetoFinal/node_modules/mysql/lib/protocol/sequences/Query.js:72:10)
    at Protocol._parsePacket (/Users/joaomiguelrodrigues/Desktop/FCUL/ProjetoFinal/node_modules/mysql/lib/protocol/Protocol.js:280:23)

I tried doing this because the getter was returning an empty array, even thou I entered an insert query into database.

Does anyone know why this happens? Or how to solve this? Thanks!

Versions:
"node": "^3.10.9",
"mysql": "^2.13.0",
"orm": "^3.2.3",

@dxg
Copy link
Collaborator

dxg commented May 22, 2017

How are you calling .save ?

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

No branches or pull requests

2 participants