Quick ORM
Search…
Retrieving Relationships
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.
1
var posts = user.getPosts();
Copied!
The second is as a relationship. Calling user.posts() returns a Relationship instance to retrieve the posts that can be further constrained. A Relationship is backed by qb as well, so feel free to call any qb method to further constrain the relationship.
1
var newestPosts = user
2
.posts()
3
.orderBy( "publishedDate", "desc" )
4
.get();
Copied!
You can also call the other Quick fetch methods: first, firstOrFail, find, and findOrFail are all supported. This is especially useful to constrain the entities available to a user by using the user's relationships:
1
// This will only find posts the user has written.
2
var post = user.posts().findOrFail( rc.id );
Copied!
Last modified 2yr ago
Copy link
Edit on GitHub