<commit_before><?php
namespace Resto\Relations;

use Resto\Common\Module as Resource;
use Resto\Common\Str;
use Resto\Entity\Collection;

class HasMany extends Relation
{
	/**
	 * Build URL path using calling and relating model
	 * @return string
	 */
	protected function buildQueryPath()
	{
		//ie:- users/1
		$caller_path    = $this->getCallingModel()->getEntityPath();

		//ie:- posts
		$relatives_path = Str::collectionPath($this->getRelatingModel());

		//ie:- users/1/posts
		return implode('/', array($caller_path, $relatives_path));
	}

	public function getFromModel($attribute)
	{
		return new Collection($this->getInModelData($attribute));
	}
}<commit_msg>added insert method to add related models<commit_after><?php
namespace Resto\Relations;

use Resto\Common\Module as Resource;
use Resto\Common\Str;
use Resto\Entity\Collection;
use Resto\Entity\Model;

class HasMany extends Relation
{
	/**
	 * Build URL path using calling and relating model
	 * @return string
	 */
	protected function buildQueryPath()
	{
		//ie:- users/1
		$caller_path    = $this->getCallingModel()->getEntityPath();

		//ie:- posts
		$relatives_path = Str::collectionPath($this->getRelatingModel());

		//ie:- users/1/posts
		return implode('/', array($caller_path, $relatives_path));
	}

	public function getFromModel($attribute)
	{
		return new Collection($this->getInModelData($attribute));
	}

	/**
	 * Insert a related model
	 * @return [type] [description]
	 */
	public function insert(Model $model)
	{
		$model->setCollectionPath($this->buildQueryPath());
		return $model->save();
	}
}
{'fraction_non_alphanumeric': 0.1438529784537389, 'fraction_numerical': 0.0025348542458808617, 'mean_word_length': 4.426116838487973, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1533068', 'n_tokens_mistral': 526, 'n_tokens_neox': 492, 'n_words': 118}