-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Scopes): Register global scopes for entities
Each entity can define a `applyGlobalScopes` method that calls one or more scopes on the entity. These scopes will be applied to each query method. Additionally, these scopes can be ignored once using a `withoutGlobalScope` method when defining the query.
- Loading branch information
Showing
3 changed files
with
53 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
component extends="User" table="users" { | ||
|
||
function applyGlobalScopes() { | ||
this.withLatestPostId(); | ||
this.ofType( "admin" ); | ||
} | ||
|
||
} |
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,20 @@ | ||
component extends="tests.resources.ModuleIntegrationSpec" appMapping="/app" { | ||
|
||
function run() { | ||
describe( "Global Scopes Spec", function() { | ||
it( "can add a global scope to an entity", function() { | ||
var admins = getInstance( "Admin" ).all(); | ||
expect( admins ).toBeArray(); | ||
expect( admins ).toHaveLength( 1 ); | ||
expect( admins[ 1 ].getId() ).toBe( 1 ); | ||
} ); | ||
|
||
it( "can run a query without a global scope", function() { | ||
var admins = getInstance( "Admin" ).withoutGlobalScope( "ofType" ).all(); | ||
expect( admins ).toBeArray(); | ||
expect( admins ).toHaveLength( 3 ); | ||
} ); | ||
} ); | ||
} | ||
|
||
} |