Created
January 12, 2016 07:32
-
-
Save prewk/260d118749260c0a77e9 to your computer and use it in GitHub Desktop.
Bookshelf.js polymorphic problem
This file contains hidden or 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
var bookshelf = require('./bookshelf'); | |
var Post = require('./post'); | |
/* | |
Schema: | |
posts: | |
id: PRIMARY | |
title: VARCHAR | |
tags: | |
id: PRIMARY | |
tag: VARCHAR | |
taggable: | |
id: PRIMARY | |
tag_id: UNSIGNED INT | |
taggable_id: UNSIGNED INT | |
taggable_type: VARCHAR | |
*/ | |
var bookshelf = require('./bookshelf'); | |
var Tag = require('./tag'); | |
var Post = require('./post'); | |
var Taggable = bookshelf.Model.extend({ | |
tableName: 'taggables', | |
taggable: function() { | |
return this.morphTo('taggable', Post); | |
} | |
}); | |
// How do I specify that taggable morphs tags? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment