Skip to content
Merged
Show file tree
Hide file tree
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
22 changes: 21 additions & 1 deletion lib/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,27 @@ public function &__get($name)
*/
public function __isset($attribute_name)
{
return array_key_exists($attribute_name, $this->attributes) || array_key_exists($attribute_name, static::$alias_attribute);
// check for aliased attribute
if (array_key_exists($attribute_name, static::$alias_attribute)) {
return true;
}

// check for attribute
if (array_key_exists($attribute_name, $this->attributes)) {
return true;
}

// check for getters
if (method_exists($this, "get_${attribute_name}")) {
return true;
}

// check for relationships
if (static::table()->has_relationship($attribute_name)) {
return true;
}

return false;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions test/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ public function test_isset()
$book = new Book();
$this->assert_true(isset($book->name));
$this->assert_false(isset($book->sharks));

$author = Author::find(1);
$this->assert_true(isset($author->awesome_person));
}

public function test_readonly_only_halt_on_write_method()
Expand Down
1 change: 0 additions & 1 deletion test/RelationshipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,6 @@ public function test_eager_loading_has_many_array_of_includes()

foreach ($assocs as $assoc) {
$this->assert_internal_type('array', $authors[1]->$assoc);
$this->assert_true(empty($authors[1]->$assoc));
}

$this->assert_sql_has('WHERE author_id IN(?,?)', ActiveRecord\Table::load('Author')->last_sql);
Expand Down