Last active
December 27, 2015 10:09
-
-
Save james-lukensow/7308564 to your computer and use it in GitHub Desktop.
Adding a hasMany association
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Node v0.10.2 | |
Geddy v0.10.5 | |
// Snipped of code in my lib | |
keywordTopic = _.find(topics, { 'slug': 'xbox' }); | |
// keywordTopic -> http://pastebin.com/fbPtug5B | |
tweet = geddy.model.Tweet.create({ | |
lookupSlug: _.uniq(lookupSlug, true), | |
keywords: keyword, | |
tweet: data | |
}); | |
tweet.save(function(err, data) { | |
if (err) { | |
console.log(err); | |
} | |
tweet.addTopic(keywordTopic); | |
console.log('Assocationed Added', tweet); | |
// Updated Pastbin now using the Associated model | |
// -> http://pastebin.com/yJzCqUTm | |
tweet.save(function(err, data) { | |
console.log('Save Assocation', data); | |
// Updated Pastbin with new tweet.save | |
// -> http://pastebin.com/8SFjpHgX | |
}) | |
}); | |
// Models | |
// Topic Model | |
var Topic = function () { | |
this.property('name', 'string', {required:true}); | |
this.property('slug', 'string'); | |
this.property('order', 'int'); | |
this.property('published', 'boolean'); | |
this.property('seoTitle', 'string'); | |
this.property('seoDescription', 'string'); | |
this.property('seoKeywords', 'string'); | |
this.hasMany('Tweet', {through: 'Tweettopic'}); | |
}; | |
exports.Topic = Topic; | |
//Tweet Model | |
var Tweet = function () { | |
this.property('keywords', 'object'); | |
this.property('lookupSlug', 'object'); | |
this.property('tweet', 'object'); | |
this.hasMany('Topic', {through: 'Tweettopic'}); | |
}; | |
exports.Tweet = Tweet; | |
//Assocation Model | |
var Tweettopic = function () { | |
this.hasMany('Tweet'); | |
this.hasMany('Topic'); | |
}; | |
exports.Tweettopic = Tweettopic; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment