Permalink
Browse files

Getting started on 'through' associations

  • Loading branch information...
1 parent 121c193 commit b6653f713ef04a4b0a974347ddded4b1ea3fa40b mde committed Mar 28, 2013
Showing with 33 additions and 1 deletion.
  1. +3 −1 test/adapters/shared.js
  2. +14 −0 test/fixtures/membership.js
  3. +13 −0 test/fixtures/team.js
  4. +3 −0 test/fixtures/user.js
View
@@ -6,7 +6,9 @@ var utils = require('utilities')
, Zooby = require('../fixtures/zooby').Zooby
, User = require('../fixtures/user').User
, Profile = require('../fixtures/profile').Profile
- , Account = require('../fixtures/account').Account;
+ , Account = require('../fixtures/account').Account
+ , Team = require('../fixtures/team').Team
+ , Membership = require('../fixtures/membership').Membership;
tests = {
@@ -0,0 +1,14 @@
+var model = require('../../lib');
+
+var Membership = function () {
+ this.property('name', 'string', {required: true});
+
+ this.belongsTo('User');
+ this.belongsTo('Team');
+};
+
+Membership = model.register('Membership', Membership);
+
+module.exports.Membership = Membership;
+
+
View
@@ -0,0 +1,13 @@
+var model = require('../../lib');
+
+var Team = function () {
+ this.property('name', 'string', {required: true});
+
+ this.hasMany('Memberships');
+ this.hasMany('Users', {through: 'Memberships'});
+};
+
+Team = model.register('Team', Team);
+
+module.exports.Team = Team;
+
View
@@ -16,6 +16,9 @@ var User = function () {
this.hasMany('Accounts');
this.hasMany('Kids', {model: 'Users'});
this.hasMany('Avatars', {model: 'Profiles'});
+ this.hasMany('Memberships');
+ this.hasMany('Teams', {through: 'Memberships'});
+
};
User.prototype.someMethod = function () {

0 comments on commit b6653f7

Please sign in to comment.