Quick ORM
2.1.0
2.1.0
  • Introduction
  • What's New?
  • Upgrade Guide
  • Getting Started
    • Defining An Entity
    • Retrieving Entities
    • Creating New Entities
    • Updating Existing Entities
    • Deleting Entities
    • Query Scopes
  • Relationships
    • Relationship Types
      • hasOne
      • hasMany
      • belongsTo
      • belongsToMany
      • hasManyThrough
      • polymorphicBelongsTo
      • polymorphicHasMany
    • Retrieving Relationships
    • Eager Loading
  • CBORM Compatibility Shim
  • Collections
  • Custom Getters & Setters
  • Serialization
  • Interception Points
  • Debugging
  • Contributing
Powered by GitBook
On this page

Was this helpful?

Edit on Git
Export as PDF
  1. Relationships

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.

var posts = user.getPosts();

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.

var newestPosts = user
    .posts()
    .orderBy( "publishedDate", "desc" )
    .get();
PreviouspolymorphicHasManyNextEager Loading

Last updated 6 years ago

Was this helpful?