/** * @param string $property * @param AbstractResultSet $resultSet * @param array|string $keys * @param string $cardinality optional [many|one] */ public function relate($property, $resultSet, $keys, $cardinality = 'many') { $this->keys = $keys; $this->cardinality = $cardinality; foreach ($resultSet as $object) { $this->relations[$property][ObjectProperty::get($keys[1], $object)][] = $object; } }
/** * Returns the primary query for an object or a class if $params is a object * the parameters of the object will be used if not the value will be used * * @param string $className * @param string|object|array $params * @param string $prefix * @throws EQMException * @return object the result contains a query and a params parameter */ protected static function primaryQuery($className, $params = null, $prefix = '') { $query = ''; $queryParams = []; // TODO check for assoc arrays necessary $isNotAssoc = false; if (!is_object($params) && !is_array($params)) { $params = [$params]; $isNotAssoc = true; } foreach (static::tableMeta($className)->getPrimary() as $primary) { $query .= (!empty($query) ? ' AND ' : ' ') . $primary . ' = :' . $prefix . $primary; if (is_object($params)) { $queryParams[$prefix . $primary] = ObjectProperty::get($primary, $params); if ($queryParams[$prefix . $primary] == null) { throw new EQMException('null is not a valid parameter for a primary query', 9003); } } else { if ($isNotAssoc) { $queryParams[$prefix . $primary] = array_shift($params); } else { $queryParams[$prefix . $primary] = $params[$primary]; } } } return (object) ['query' => $query, 'params' => $queryParams]; }