You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the docs, it states you can retrieve entities through a relationship definition. However, it only seems to work with some entity getters like first(), get(), etc. If you try to get an entity using something like firstOrNew(), it will return an instance of the relationship itself instead of the entity class you expected.
firstOrNew() is a very important getter because it allows you to implement the null object pattern so you can call isLoaded() on the resulting response to see if a match was found or not.
Here's a sample relationship definition to trigger the issue:
// Category entity
// category has many posts
function posts() {
return hasMany( "Post", "postId" );
}
Now try to retrieve an array of Post entities in your handler. The first way works, but the second does not!
// works!
prc.category.posts().where( "id", "=", 1 ).first(); // Returns instance of 'Post`
// does not work!
prc.category.posts().where( "id", "=", 1 ).firstOrNew(); // Returns instance of 'quick.models.Relationships.HasMany'
The text was updated successfully, but these errors were encountered:
In the docs, it states you can retrieve entities through a relationship definition. However, it only seems to work with some entity getters like
first()
,get()
, etc. If you try to get an entity using something likefirstOrNew()
, it will return an instance of the relationship itself instead of the entity class you expected.firstOrNew()
is a very important getter because it allows you to implement the null object pattern so you can callisLoaded()
on the resulting response to see if a match was found or not.Here's a sample relationship definition to trigger the issue:
Now try to retrieve an array of
Post
entities in your handler. The first way works, but the second does not!The text was updated successfully, but these errors were encountered: