Reputation: 41865
The PHP orm Granada based on Idiorm works the following way to retrieve fields from database:
class ORM {
...
public function __get($key) {
return $this->get($key);
}
}
class ORMWrapper extends ORM {
...
public function get($key) {
if (method_exists($this, 'get_' . $key)) {
return $this->{'get_' . $key}();
} elseif (array_key_exists($key, $this->_data)) {
return $this->_data[$key];
}
elseif (array_key_exists($key, $this->ignore)) {
return $this->ignore[$key];
}
// and so on ...
}
My problem is that if I define public $field
in my model classes, the magic method __get is not called, and so the ORM does not retrieve the field from the database?
How can I
public $field
in my model classes$field
is undefinedAt the same time?
Upvotes: 0
Views: 575
Reputation: 41865
All I actually wanted to do is the have the autocompletion working on netbeans.
Just declaring my Model classes like that did the job:
/**
* @property int $address_id
* @property Address $address
* @property String $name
* ...
*/
class Activity extends Model {
public function address() {
return $this->belongs_to('Address');
}
//...
}
This way I can do
$activity->address->name;
And I have the completion and the ORM both working.
Upvotes: 1