Skip to content

Instantly share code, notes, and snippets.

@uncletammy
Created November 7, 2014 21:35
Show Gist options
  • Save uncletammy/a822c8bf926ecb8ecd09 to your computer and use it in GitHub Desktop.
Save uncletammy/a822c8bf926ecb8ecd09 to your computer and use it in GitHub Desktop.
One-To-One Associations Issue
/**
* Pet.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
owner: {
model: 'user'
}
}
};
dude@littleDude:~/node/trashApp$ rm .tmp/localDiskDb.db
dude@littleDude:~/node/trashApp$ sails console
info: Starting app in interactive mode...
info: Welcome to the Sails console.
info: ( to exit, type <CTRL>+<C> )
sails> User.create({name:'rick',petName:{name:'spot'}}).exec(console.log);
undefined
sails> null { name: 'rick',
petName: 1,
createdAt: Fri Nov 07 2014 15:33:48 GMT-0600 (CST),
updatedAt: Fri Nov 07 2014 15:33:48 GMT-0600 (CST),
id: 1 }
User.find().populate('petName').exec(console.log)
undefined
sails> null [ { petName:
{ name: 'spot',
createdAt: Fri Nov 07 2014 15:33:48 GMT-0600 (CST),
updatedAt: Fri Nov 07 2014 15:33:48 GMT-0600 (CST),
id: 1 },
name: 'rick',
createdAt: Fri Nov 07 2014 15:33:48 GMT-0600 (CST),
updatedAt: Fri Nov 07 2014 15:33:48 GMT-0600 (CST),
id: 1 } ]
sails> Pet.find().populate('owner').exec(console.log)
undefined
sails> null [ { name: 'spot',
createdAt: Fri Nov 07 2014 15:33:48 GMT-0600 (CST),
updatedAt: Fri Nov 07 2014 15:33:48 GMT-0600 (CST),
id: 1,
owner: undefined } ]
/**
* User.js
*
* @description :: TODO: You might write a short summary of how this model works and what it represents here.
* @docs :: http://sailsjs.org/#!documentation/models
*/
module.exports = {
attributes: {
petName: {
model: 'pet'
}
}
};
@uncletammy
Copy link
Author

Using versions

Sails.js: v.0.10.5
Waterline: v.0.10.12
Sails-disk: v.0.10.4

Is this expected behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment