Skip to content

Commit aec1aa9

Browse files
committed
Add __isset to entities
1 parent 688f4ea commit aec1aa9

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Traits/EntityTrait.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,36 @@ public function __get(string $key)
4848
return null;
4949
}
5050

51+
/**
52+
* Complimentary property checker to __get()
53+
*
54+
* @param string $key The name of the requested property, i.e. table to check for relations
55+
*
56+
* @return bool Whether the entity property or table relation exists
57+
*/
58+
public function __isset(string $key): bool
59+
{
60+
// First check the framework's version
61+
if (parent::__isset($key))
62+
{
63+
return true;
64+
}
65+
66+
// Get the schema
67+
$schema = $this->_schema();
68+
69+
// Convert the key to table format
70+
$tableName = plural(strtolower($key));
71+
72+
// Check for a matching table
73+
if (isset($schema->tables->$tableName))
74+
{
75+
return true;
76+
}
77+
78+
return false;
79+
}
80+
5181
/**
5282
* Intercept undefined methods and check them against known relations
5383
*

0 commit comments

Comments
 (0)