src/SnooPHP/Model/Model.php
public function hasMany($forClass, $forColumn = null, $condition = "", array $conditionParams = [])
	{
		$refTable = static::tableName();
		$forTable = $forClass::tableName();
		$refColumn = static::$idColumn;
		$forColumn = $forColumn ?: strtolower(static::modelName())."_id";

		$rows = Db::query("
			select F.*
			from $refTable as R, $forTable as F
			where R.$refColumn = F.$forColumn and R.$refColumn = :id $condition
		", array_merge(["id" => $this->$refColumn], $conditionParams), static::getDbName());

		if ($rows === false)
			return false;
		if (empty($rows))
			return new Collection([]);

		// Populate models
		$collection = [];
		foreach ($rows as $row)
		{
			$forModel = new $forClass;
			foreach ($row as $column => $val) $forModel->$column = $forModel->decodeValue($val, $column);
			$collection[] = $forModel;
		}
		
		return new Collection($collection);
	}
public function hasMany($forClass, $forColumn = null, $condition = "", array $conditionParams = [])
	{
		$refTable = static::tableName();
		$forTable = $forClass::tableName();
		$refColumn = static::$idColumn;
		$forColumn = $forColumn ?: strtolower(static::modelName())."_id";

		$rows = Db::query("
			select F.*
			from $refTable as R, $forTable as F
			where R.$refColumn = F.$forColumn and R.$refColumn = :id $condition
		", array_merge(["id" => $this->$refColumn], $conditionParams), static::getDbName());

		if ($rows === false)
			return false;
		if (empty($rows))
			return new Collection([]);

		// Populate models
		$collection = [];
		foreach ($rows as $row)
		{
			$forModel = new $forClass;
			foreach ($row as $column => $val) $forModel->$column = $forModel->decodeValue($val, $column);
			$collection[] = $forModel;
		}
		
		return new Collection($collection);
	}
One-to-many relationship

@param string	$forClass			foreign model class name
@param string	$forColumn			foreign column if it differs from className_id (ex. user_id)
@param string	$condition			condition to append (AND) to the query (use R and F as Reference and Foreign tables)
@param array		$conditionParams	parameters to bind to the condition query

@return Collection|null collection of foreign models