public function __construct($modelClass, $kind, $owner, $foreignKey) { $this->kind = $kind; $this->owner = $owner; $this->foreignKey = $foreignKey; parent::__construct($modelClass); }
public function build_query() { $params = $this->params; if (empty($params['foreign_key'])) { $inflector = \Rails::services()->get('inflector'); $cn = get_class($this->parent_model); $params['foreign_key'] = $inflector->singularize($cn::tableName()) . '_id'; } $query = new Relation($params['class_name'], $params['class_name']::tableName()); $query->where('`' . $params['foreign_key'] . "` = ?", $this->parent_model->id); # params[0], if present, it's an anonymous function to customize the relation. # The function is binded to the relation object. if (isset($this->params[0])) { $lambda = array_shift($this->params); $lambda = $lambda->bindTo($query); $lambda(); } $this->query = $query; }