private function whereRelated($relationship, $constraint)
	{
		$this->data = [];
		$keys       = null;

		// Parse for nested relationships
		if (strpos($name, '.'))
		{
			// If we have a nested name, pull out the first one
			list($name, $subs)  = explode('.', $name, 2);
			$relationship       = $this->$name();
			$this->data[$name]  = $relationship->whereRelated($subs, $constraint);
		}
		else
		{
			$relationship       = $this->$name();
			$this->data[$name]  = $relationship->getConstrainedRows($constraint);
		}

		// Update keys to only include those in this and previous results
		$keys = is_null($keys) ? $relationship->getRelatedKeysFromRows($this->data[$name])
		                       : array_intersect($keys, $relationship->getRelatedKeysFromRows($this->data[$name]));

		// Only keep unique keys
		$keys = array_unique($keys);

		// Set our where clause if needed
		if (!empty($keys))
		{
			$this->whereIn($relationship->getLocalKey(), $keys);
		}

		return $this;
	}
private function whereRelated($relationship, $constraint)
	{
		$this->data = [];
		$keys       = null;

		// Parse for nested relationships
		if (strpos($name, '.'))
		{
			// If we have a nested name, pull out the first one
			list($name, $subs)  = explode('.', $name, 2);
			$relationship       = $this->$name();
			$this->data[$name]  = $relationship->whereRelated($subs, $constraint);
		}
		else
		{
			$relationship       = $this->$name();
			$this->data[$name]  = $relationship->getConstrainedRows($constraint);
		}

		// Update keys to only include those in this and previous results
		$keys = is_null($keys) ? $relationship->getRelatedKeysFromRows($this->data[$name])
		                       : array_intersect($keys, $relationship->getRelatedKeysFromRows($this->data[$name]));

		// Only keep unique keys
		$keys = array_unique($keys);

		// Set our where clause if needed
		if (!empty($keys))
		{
			$this->whereIn($relationship->getLocalKey(), $keys);
		}

		return $this;
	}
private function whereRelated ( $ relationship , $ constraint ) { $ this -> data = [ ] ; $ keys = null ; // Parse for nested relationships if ( strpos ( $ name , '.' ) ) { // If we have a nested name, pull out the first one list ( $ name , $ subs ) = explode ( '.' , $ name , 2 ) ; $ relationship = $ this -> $ name ( ) ; $ this -> data [ $ name ] = $ relationship -> whereRelated ( $ subs , $ constraint ) ; } else { $ relationship = $ this -> $ name ( ) ; $ this -> data [ $ name ] = $ relationship -> getConstrainedRows ( $ constraint ) ; } // Update keys to only include those in this and previous results $ keys = is_null ( $ keys ) ? $ relationship -> getRelatedKeysFromRows ( $ this -> data [ $ name ] ) : array_intersect ( $ keys , $ relationship -> getRelatedKeysFromRows ( $ this -> data [ $ name ] ) ) ; // Only keep unique keys $ keys = array_unique ( $ keys ) ; // Set our where clause if needed if ( ! empty ( $ keys ) ) { $ this -> whereIn ( $ relationship -> getLocalKey ( ) , $ keys ) ; } return $ this ; }
Limits current model based on conditions of relationship

@FIXME: decide whether or not to use this

This is NOT currently used. The problem here has to do with relationship data.
If you constrain based on a relationship, and then later on end up wanting to access
properties of that relationship, it will currently do two queries.  Instead, we
could get the data with the original constraint and attach it to the models in a
similar fashion to the way that including() works.

To make this work, data would need to be stored on the object, and then seeded
after the model rows are fetched (like parseIncludes() works now).

@return  $this
@since   2.0.0
Limits current model based on conditions of relationship