Example #1
0
 public function hasManyThrough($targetClassName, $joinTableName = null, $baseKey = null, $targetKey = null)
 {
     $model = Model::make($targetClassName);
     if (is_null($joinTableName)) {
         $tables = array($this->orm->tableName, $model->orm->tableName);
         sort($tables, SORT_STRING);
         $joinTableName = join("_", $tables);
     }
     if (is_null($baseKey)) {
         $baseKey = Str::camel($this->orm->tableName) . "ID";
     }
     if (is_null($targetKey)) {
         $targetKey = Str::camel($model->orm->tableName) . "ID";
     }
     return $model->select($model->orm->tableName . ".*")->join($joinTableName, array($model->orm->tableName . ".id", "=", $joinTableName . "." . $targetKey))->whereEqual($joinTableName . "." . $baseKey, $this->id);
 }