Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Non-Loaded Entities to Return Null Values for Relationships #178

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 4 additions & 37 deletions models/BaseEntity.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -1776,10 +1776,6 @@ component accessors="true" {
) {
param arguments.relationMethodName = lCase( callStackGet()[ 2 ][ "Function" ] );

guardAgainstNotLoaded(
"This instance is not loaded so it cannot access the [#arguments.relationMethodName#] relationship. Either load the entity from the database using a query executor (like `first`) or base your query off of the [#arguments.relationName#] entity directly and use the `has` or `whereHas` methods to constrain it based on data in [#entityName()#]."
);

var related = variables._wirebox.getInstance( arguments.relationName );

// ACF doesn't let us use param with functions. ¯\_(ツ)_/¯
Expand Down Expand Up @@ -1836,10 +1832,6 @@ component accessors="true" {
) {
param arguments.relationMethodName = lCase( callStackGet()[ 2 ][ "Function" ] );

guardAgainstNotLoaded(
"This instance is not loaded so it cannot access the [#arguments.relationMethodName#] relationship. Either load the entity from the database using a query executor (like `first`) or base your query off of the [#arguments.relationName#] entity directly and use the `has` or `whereHas` methods to constrain it based on data in [#entityName()#]."
);

var related = variables._wirebox.getInstance( arguments.relationName );

if ( isNull( arguments.foreignKey ) ) {
Expand Down Expand Up @@ -1891,10 +1883,6 @@ component accessors="true" {
) {
param arguments.relationMethodName = lCase( callStackGet()[ 2 ][ "Function" ] );

guardAgainstNotLoaded(
"This instance is not loaded so it cannot access the [#arguments.relationMethodName#] relationship. Either load the entity from the database using a query executor (like `first`) or base your query off of the [#arguments.relationName#] entity directly and use the `has` or `whereHas` methods to constrain it based on data in [#entityName()#]."
);

var related = variables._wirebox.getInstance( arguments.relationName );

if ( isNull( arguments.foreignKey ) ) {
Expand Down Expand Up @@ -1964,10 +1952,6 @@ component accessors="true" {
) {
param arguments.relationMethodName = lCase( callStackGet()[ 2 ][ "Function" ] );

guardAgainstNotLoaded(
"This instance is not loaded so it cannot access the [#arguments.relationMethodName#] relationship. Either load the entity from the database using a query executor (like `first`) or base your query off of the [#arguments.relationName#] entity directly and use the `has` or `whereHas` methods to constrain it based on data in [#entityName()#]."
);

var related = variables._wirebox.getInstance( arguments.relationName );

param arguments.table = generateDefaultPivotTableString( related.tableName(), tableName() );
Expand Down Expand Up @@ -2063,10 +2047,6 @@ component accessors="true" {

param arguments.relationMethodName = lCase( callStackGet()[ 2 ][ "Function" ] );

guardAgainstNotLoaded(
"This instance is not loaded so it cannot access the [#arguments.relationMethodName#] relationship. Either load the entity from the database using a query executor (like `first`) or base your query off of the [#arguments.relationships[ arguments.relationships.len() ]#] entity directly and use the `has` or `whereHas` methods to constrain it based on data in [#entityName()#]."
);

// this is set here for the first case where the previousEntity is
// `this` entity and we don't want to double prefix
var aliasPrefix = variables._aliasPrefix;
Expand Down Expand Up @@ -2134,10 +2114,6 @@ component accessors="true" {

param arguments.relationMethodName = lCase( callStackGet()[ 2 ][ "Function" ] );

guardAgainstNotLoaded(
"This instance is not loaded so it cannot access the [#arguments.relationMethodName#] relationship. Either load the entity from the database using a query executor (like `first`) or base your query off of the [#arguments.relationships[ arguments.relationships.len() ]#] entity directly and use the `has` or `whereHas` methods to constrain it based on data in [#entityName()#]."
);

// this is set here for the first case where the previousEntity is
// `this` entity and we don't want to double prefix
var aliasPrefix = variables._aliasPrefix;
Expand Down Expand Up @@ -2205,10 +2181,6 @@ component accessors="true" {

param arguments.relationMethodName = lCase( callStackGet()[ 2 ][ "Function" ] );

guardAgainstNotLoaded(
"This instance is not loaded so it cannot access the [#arguments.relationMethodName#] relationship. Either load the entity from the database using a query executor (like `first`) or base your query off of the [#arguments.relationships[ arguments.relationships.len() ]#] entity directly and use the `has` or `whereHas` methods to constrain it based on data in [#entityName()#]."
);

// this is set here for the first case where the previousEntity is
// `this` entity and we don't want to double prefix
var aliasPrefix = variables._aliasPrefix;
Expand Down Expand Up @@ -2279,10 +2251,6 @@ component accessors="true" {
) {
param arguments.relationMethodName = lCase( callStackGet()[ 2 ][ "Function" ] );

guardAgainstNotLoaded(
"This instance is not loaded so it cannot access the [#arguments.relationMethodName#] relationship. Either load the entity from the database using a query executor (like `first`) or base your query off of the [#arguments.relationName#] entity directly and use the `has` or `whereHas` methods to constrain it based on data in [#entityName()#]."
);

var related = variables._wirebox.getInstance( arguments.relationName );

param arguments.type = arguments.name & "_type";
Expand Down Expand Up @@ -2336,10 +2304,6 @@ component accessors="true" {
param arguments.relationMethodName = lCase( callStackGet()[ 2 ][ "Function" ] );
param arguments.name = arguments.relationMethodName;

guardAgainstNotLoaded(
"This instance is not loaded so it cannot access the [#arguments.relationMethodName#] relationship. Either load the entity from the database using a query executor (like `first`) or base your query off of the related polymorphic entity directly and use the `has` or `whereHas` methods to constrain it based on data in [#entityName()#]."
);

param arguments.type = arguments.name & "_type";
param arguments.id = arguments.name & "_id";
arguments.id = arrayWrap( arguments.id );
Expand Down Expand Up @@ -3749,7 +3713,10 @@ component accessors="true" {
* @return Boolean
*/
public boolean function isNullValue( required string key, any value ) {
param arguments.value = invoke( this, "get" & arguments.key );
if ( isNull( arguments.value ) ) {
return true;
}
param arguments.value = invoke( this, "get" & arguments.key );
var alias = retrieveAliasForColumn( arguments.key );
if ( !isSimpleValue( arguments.value ) ) {
return false;
Expand Down