-
Notifications
You must be signed in to change notification settings - Fork 376
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
Setting model created with 'extendsTo' fails with 'ER_NO_DEFAULT_FOR_FIELD' #250
Comments
I'm getting a bad query to update |
Get the latest commit and change your code to this: var orm = require('orm');
var slug = require('slugg');
module.exports = function( db ){
var User = db.models.user;
var Room = db.define( 'room', {
title: {
type: 'text',
required: true,
unique: true
},
slug: String,
subtitle: {
type: 'text',
defaultValue: 'A great place to share with friends!'
},
active: Boolean,
'private': Boolean
}, {
hooks: {
beforeSave: function( next ){
this.slug = slug( this.title );
next();
}
}
});
Room.extendsTo( 'player', {
order: {
type: 'text',
defaultValue: 'normal'
},
max_duration: {
type: 'number',
defaultValue: 60 // minutes
},
providers: Object,
item: Object
});
Room.hasOne( 'creator', User, {
reverse: 'rooms'
});
Room.start = function( data, user_id, cb ){
cb = cb || function(){};
User.get( user_id, function( err, user ){
if( !user ) return cb( err || new Error('User could not be found.'), null );;
Room.create( data, function( err, room ){
if( !room ) return cb( err || new Error('Room could not be created.'), null );
room.setCreator( user, function( err ){
if( err ) return cb( err, null );
var roomPlayer = {
providers: {
youtube: true,
soundcloud: true,
vimeo: true
}
};
room.setPlayer( roomPlayer, function( err ){
return cb( null, room );
});
});
});
});
};
return Room;
};
|
And don't forget: Room.hasMany("players", User, {
order: ...,
max_duration: ...
});
// ...
some_room.addPlayers(user1, user2, ..., function () {
// added!
}); |
Well, the bug I thought existed just vanished with my change 😄 |
I'm going to try this out tonight, I'll get back to you on this in about 8 hours... |
Looks like both |
I'm going to release it in the end of the week. |
No matter what I try to do, I can't seem to get past this error when I attempt to use
RoomPlayer.create
:My room model is as follows:
My first guess is that I'm just doing something wrong, but the documentation for extendsTo doesn't clearly illustrate how to use the extended model.
The text was updated successfully, but these errors were encountered: