1414 * @package UserFrosting
1515 * @author Alex Weissman
1616 */
17- abstract class UFModel extends Model {
17+ abstract class UFModel extends Model
18+ {
1819
1920 /**
2021 * @var Slim The Slim app, containing configuration info
@@ -35,7 +36,8 @@ abstract class UFModel extends Model {
3536 * Create a new object, initializing the table name and whitelisted columns.
3637 *
3738 */
38- public function __construct ($ properties = []) {
39+ public function __construct ($ properties = [])
40+ {
3941 $ table_schema = Database::getSchemaTable (static ::$ _table_id );
4042 $ this ->table = $ table_schema ->name ;
4143 $ this ->fillable = $ table_schema ->columns ;
@@ -45,19 +47,32 @@ public function __construct($properties = []) {
4547 }
4648
4749 /**
48- * For raw array fetching. Must be static, otherwise PHP gets confused about where to find the table_id.
49- */
50- public static function queryBuilder (){
51- // Set query builder to fetch result sets as associative arrays (instead of creating stdClass objects)
52- Capsule::connection ()->setFetchMode (\PDO ::FETCH_ASSOC );
53- $ table = Database::getSchemaTable (static ::$ _table_id )->name ;
54- return Capsule::table ($ table );
50+ * Determine if an attribute exists on the model - even if it is null.
51+ *
52+ * @param string $key
53+ * @return bool
54+ */
55+ public function attributeExists ($ key )
56+ {
57+ return array_key_exists ($ key , $ this ->attributes );
58+ }
59+
60+ /**
61+ * Determine if an relation exists on the model - even if it is null.
62+ *
63+ * @param string $key
64+ * @return bool
65+ */
66+ public function relationExists ($ key )
67+ {
68+ return array_key_exists ($ key , $ this ->relations );
5569 }
5670
5771 /**
5872 * For excluding certain columns in a query.
5973 */
60- public function scopeExclude ($ query , $ value = []) {
74+ public function scopeExclude ($ query , $ value = [])
75+ {
6176 $ columns = array_merge (['id ' ], Database::getSchemaTable (static ::$ _table_id )->columns );
6277 return $ query ->select ( array_diff ( $ columns ,(array ) $ value ) );
6378 }
@@ -68,7 +83,8 @@ public function scopeExclude($query, $value = []) {
6883 * Calls save(), then returns the id of the new record in the database.
6984 * @return int the id of this object.
7085 */
71- public function store (){
86+ public function store ()
87+ {
7288 $ this ->save ();
7389
7490 // Store function should always return the id of the object
@@ -80,7 +96,19 @@ public function store(){
8096 *
8197 * @return array
8298 */
83- public function export (){
99+ public function export ()
100+ {
84101 return $ this ->toArray ();
85- }
102+ }
103+
104+ /**
105+ * For raw array fetching. Must be static, otherwise PHP gets confused about where to find the table_id.
106+ */
107+ public static function queryBuilder ()
108+ {
109+ // Set query builder to fetch result sets as associative arrays (instead of creating stdClass objects)
110+ Capsule::connection ()->setFetchMode (\PDO ::FETCH_ASSOC );
111+ $ table = Database::getSchemaTable (static ::$ _table_id )->name ;
112+ return Capsule::table ($ table );
113+ }
86114}
0 commit comments