This repository has been archived by the owner on Feb 10, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automatically set collection name, if missing
- Loading branch information
vdemedes
committed
Feb 16, 2015
1 parent
35d9bc1
commit 29e4ab5
Showing
8 changed files
with
109 additions
and
21 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var pluralize = require('pluralize'); | ||
|
||
class Model { | ||
_collection () { | ||
if (!this.collection) { | ||
this.collection = this.constructor.prototype.collection = pluralize(this.constructor.name).toLowerCase(); | ||
} | ||
|
||
return this.collection; | ||
} | ||
|
||
find () { | ||
this._collection(); | ||
} | ||
} | ||
|
||
class User extends Model { | ||
|
||
} | ||
|
||
class Account extends Model { | ||
|
||
} | ||
|
||
var account = new Account(); | ||
console.log(account.collection); | ||
account.find(); | ||
console.log(account.collection); | ||
account = new Account(); | ||
console.log(account.collection); |
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,21 @@ | ||
/** | ||
* Dependencies | ||
*/ | ||
|
||
var Model = require('../../').Model; | ||
|
||
|
||
/** | ||
* Account model | ||
*/ | ||
|
||
class Account extends Model { | ||
|
||
} | ||
|
||
|
||
/** | ||
* Expose `Account` | ||
*/ | ||
|
||
module.exports = Account; |
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