-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support subproperty for delegate (#61)
- Loading branch information
1 parent
7e0f9ac
commit cc30ec2
Showing
14 changed files
with
234 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
10 changes: 10 additions & 0 deletions
10
test/fixtures/apps/datasources/app/subproperty/a/Person.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const { STRING } = app.Sequelize; | ||
const Person = app.subproperty.a.define('person', { | ||
name: STRING(30), | ||
}); | ||
|
||
return Person; | ||
}; |
28 changes: 28 additions & 0 deletions
28
test/fixtures/apps/datasources/app/subproperty/a/monkey.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const { STRING, INTEGER, DATE } = app.Sequelize; | ||
const Monkey = app.subproperty.a.define('monkey', { | ||
name: { | ||
type: STRING, | ||
allowNull: false, | ||
}, | ||
user_id: INTEGER, | ||
created_at: DATE, | ||
updated_at: DATE, | ||
}, { | ||
tableName: 'the_monkeys', | ||
|
||
classMethods: { | ||
}, | ||
|
||
instanceMethods: { | ||
}, | ||
}); | ||
|
||
Monkey.findUser = async function() { | ||
return app.subproperty.a.User.find({ id: 1 }); | ||
}; | ||
|
||
return Monkey; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
|
||
module.exports = app => { | ||
const { INTEGER, STRING } = app.Sequelize; | ||
const Post = app.subproperty.a.define('post', { | ||
user_id: INTEGER, | ||
name: STRING(30), | ||
}); | ||
|
||
Post.associate = function() { | ||
assert.ok(app.subproperty.a.User); | ||
assert.ok(app.subproperty.a.Post); | ||
app.subproperty.a.Post.belongsTo(app.subproperty.a.User, { as: 'user', foreignKey: 'user_id' }); | ||
}; | ||
|
||
return Post; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
|
||
module.exports = app => { | ||
const { STRING, INTEGER } = app.Sequelize; | ||
const User = app.subproperty.a.define('user', { | ||
name: STRING(30), | ||
age: INTEGER, | ||
}); | ||
|
||
User.associate = function() { | ||
assert.ok(app.subproperty.a.User); | ||
assert.ok(app.subproperty.a.Post); | ||
app.subproperty.a.User.hasMany(app.subproperty.a.Post, { as: 'posts', foreignKey: 'user_id' }); | ||
}; | ||
|
||
User.test = async function() { | ||
assert(app.config); | ||
assert(app.subproperty.a.User === this); | ||
const monkey = await app.subproperty.a.Monkey.create({ name: 'The Monkey' }); | ||
assert(monkey.id); | ||
assert(monkey.isNewRecord === false); | ||
assert(monkey.name === 'The Monkey'); | ||
}; | ||
|
||
return User; | ||
}; |
10 changes: 10 additions & 0 deletions
10
test/fixtures/apps/datasources/app/subproperty/b/Person.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const { STRING } = app.Sequelize; | ||
const Person = app.subproperty.b.define('person', { | ||
name: STRING(30), | ||
}); | ||
|
||
return Person; | ||
}; |
28 changes: 28 additions & 0 deletions
28
test/fixtures/apps/datasources/app/subproperty/b/monkey.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
const { STRING, INTEGER, DATE } = app.Sequelize; | ||
const Monkey = app.subproperty.b.define('monkey', { | ||
name: { | ||
type: STRING, | ||
allowNull: false, | ||
}, | ||
user_id: INTEGER, | ||
created_at: DATE, | ||
updated_at: DATE, | ||
}, { | ||
tableName: 'the_monkeys', | ||
|
||
classMethods: { | ||
}, | ||
|
||
instanceMethods: { | ||
}, | ||
}); | ||
|
||
Monkey.findUser = async function() { | ||
return app.subproperty.b.User.find({ id: 1 }); | ||
}; | ||
|
||
return Monkey; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
|
||
module.exports = app => { | ||
const { INTEGER, STRING } = app.Sequelize; | ||
const Post = app.subproperty.b.define('post', { | ||
user_id: INTEGER, | ||
name: STRING(30), | ||
}); | ||
|
||
Post.associate = function() { | ||
assert.ok(app.subproperty.b.User); | ||
assert.ok(app.subproperty.b.Post); | ||
app.subproperty.b.Post.belongsTo(app.subproperty.b.User, { as: 'user', foreignKey: 'user_id' }); | ||
}; | ||
|
||
return Post; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
|
||
module.exports = app => { | ||
const { STRING, INTEGER } = app.Sequelize; | ||
const User = app.subproperty.b.define('user', { | ||
name: STRING(30), | ||
age: INTEGER, | ||
}); | ||
|
||
User.associate = function() { | ||
assert.ok(app.subproperty.b.User); | ||
assert.ok(app.subproperty.b.Post); | ||
app.subproperty.b.User.hasMany(app.subproperty.b.Post, { as: 'posts', foreignKey: 'user_id' }); | ||
}; | ||
|
||
User.test = async function() { | ||
assert(app.config); | ||
assert(app.subproperty.b.User === this); | ||
const monkey = await app.subproperty.b.Monkey.create({ name: 'The Monkey' }); | ||
assert(monkey.id); | ||
assert(monkey.isNewRecord === false); | ||
assert(monkey.name === 'The Monkey'); | ||
}; | ||
|
||
return User; | ||
}; |
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