Relationships can be used in two ways.
The first is as a getter. Calling
user.getPosts()will execute the relationship, cache the result, and return it.
var posts = user.getPosts();
The second is as a relationship. Calling
Relationshipinstance to retrieve the posts that can be further constrained. A
Relationshipis backed by qb as well, so feel free to call any qb method to further constrain the relationship.
var newestPosts = user
.orderBy( "publishedDate", "desc" )
You can also call the other Quick fetch methods:
findOrFailare all supported. This is especially useful to constrain the entities available to a user by using the user's relationships:
// This will only find posts the user has written.
var post = user.posts().findOrFail( rc.id );