Skip to content

Idea/Improvement: Return Null When Requesting Relationship Data from Non Loaded Entities #177

Description

@homestar9

Related to this post on the Ortus community forums.

It would be great if, when requesting relationship data from a non-loaded (new) entity, Quick would return null (or an empty array where appropriate) just like if you performed the same operation from a loaded entity. This behavior should be more intuitive and also better follows the null object pattern.

Here's a simple example of how one might use this new change in Quick:

// Post.cfc
component 
    extends="quick.models.BaseEntity" 
    accessors="true" 
{

    // Post belongs to an Author
    function author() {
        return belongsTo( "User" );
    }

}

// Posts.cfc Handler
function index( event, rc, prc ) {
	
	// Get an existing entity, or return a new one if not found
	prc.post = getInstance( "Post" )
		.firstOrCreate( rc.id );

	// return the memento with the author (it will either be null or populated)
	return prc.post.getMemento( "author" );

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions