Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(tests): add test case for firstOrNew with aliases and columns
See #107
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
component | ||
table ="my_posts" | ||
extends ="quick.models.BaseEntity" | ||
accessors="true" | ||
{ | ||
|
||
property name="id" column="post_pk"; | ||
property name="userId" column="user_id"; | ||
property name="body"; | ||
property name="createdDate" column="created_date"; | ||
property name="modifiedDate" column="modified_date"; | ||
property name="publishedDate" column="published_date"; | ||
|
||
function author() { | ||
return belongsTo( "User", "user_id" ); | ||
} | ||
|
||
function authorWithEmptyDefault() { | ||
return belongsTo( "User", "user_id" ).withDefault(); | ||
} | ||
|
||
function authorWithDefaultAttributes() { | ||
return belongsTo( "User", "user_id" ).withDefault( { | ||
"firstName" : "Guest", | ||
"lastName" : "User" | ||
} ); | ||
} | ||
|
||
function authorWithCalllbackConfiguredDefault() { | ||
return belongsTo( "User", "user_id" ).withDefault( function( user, post ) { | ||
user.setUsername( post.getBody() ); | ||
} ); | ||
} | ||
|
||
function tags() { | ||
return belongsToMany( | ||
"Tag", | ||
"my_posts_tags", | ||
"custom_post_pk", | ||
"tag_id" | ||
); | ||
} | ||
|
||
function comments() { | ||
return polymorphicHasMany( "Comment", "commentable" ); | ||
} | ||
|
||
function country() { | ||
return belongsToThrough( [ "author", "country" ] ); | ||
} | ||
|
||
function commentingUsers() { | ||
return hasManyThrough( [ "comments", "author" ] ); | ||
} | ||
|
||
function scopeLatest( qb ) { | ||
return qb.orderBy( "created_date", "desc" ); | ||
} | ||
|
||
} |
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