私は、Mac OSX(10.10.5)に帆0.12.3とのPostgreSQL 9.3.4を使用している、と私は、私は2つのモデルを設定したthrough associationSailsJSによる関連付け:関連付けの作成方法?
を実装しようとしていますジョインテーブルとして3番目私はそれがすべての関係を作成することによって設定されていることをテストしようとしたとき、私はこのエラーを取得:
Uncaught TypeError: Cannot read property 'via' of undefined
は、ここに私のテスト(モカ/チャイ)だ - 私は、エラーが、この方法では、実際にあると思います私はそれを呼び出す別のように参加のためのモデルを作成した場合に動作するので(関連付けを作成する:ここで
describe('with orgs', function() {
beforeEach(function(done) {
var testEmail = '[email protected]';
var orgName = 'Awesome Org';
Org.create({name:orgName})
.then(function(org) {
return User.create({username:testEmail, orgs:[org]})
})
.then(function(user) {
done()
})
.catch(done);
});
it('populates empty list of orgs', function(done) {
console.log('about to call find');
User.find().populate('orgs')
.then(function(users) {
console.log('users', users);
var user = users[0]
assert.isNotNull(user.orgs);
assert.equal(user.orgs.length, 1);
done();
})
.catch(done);
});
});
は私のモデルは以下のとおりです。
user.jsのを:
module.exports = {
attributes: {
username : { type: 'email' },
orgs: {
collection: 'org',
via: 'user',
through: 'orgmembership'
}
}
};
Org.js:
module.exports = {
attributes: {
name : 'string',
users: {
collection: 'user',
via: 'org',
through: 'orgmembership'
}
},
};
OrgMembership.js:
module.exports = {
tableName: 'org_membership',
attributes: {
user: { model: 'User', columnName: 'user_id', foreignKey: true},
org: { model: 'Org', columnName: 'org_id', foreignKey: true}
}
};
私はgithubにプロジェクト全体を掲載しました。
これは同じことをしているように見えますが、同じパターンに従おうとしましたが、私のためには機能しません。
私は指針や提案をいただければ幸いです。ありがとうございました!
に適用され、これはウォーターラインのバグだったとして、パッチが適用されているように見えます[email protected]。あなたのプロジェクトでテストしたところ、期待どおりに動作しました。 – particlebanana