/**
  * Filters a query object with this item's data
  *
  * @param \Illuminate\Database\Query\Builder	$query
  * @param array									$selects
  *
  * @return void
  */
 public function filterQuery(QueryBuilder &$query, &$selects = null)
 {
     //run the parent method
     parent::filterQuery($query, $selects);
     //get the values
     $value = $this->getOption('value');
     $table = $this->getOption('table');
     $column = $this->getOption('column');
     $column2 = $this->getOption('column2');
     //if there is no value, return
     if (!$value) {
         return;
     }
     $model = $this->config->getDataModel();
     //if the table hasn't been joined yet, join it
     if (!$this->validator->isJoined($query, $table)) {
         $query->join($table, $model->getTable() . '.' . $model->getKeyName(), '=', $column);
     }
     //add where clause
     $query->whereIn($column2, $value);
     //add having clauses
     $query->havingRaw('COUNT(DISTINCT ' . $query->getConnection()->getTablePrefix() . $column2 . ') = ' . count($value));
     //add select field
     if ($selects && !in_array($column2, $selects)) {
         $selects[] = $column2;
     }
 }
 /**
  * Filters a query object with this item's data given a model
  *
  * @param  \Illuminate\Database\Query\Builder	$query
  * @param  array									$selects
  * @return void
  */
 public function filterQuery(QueryBuilder &$query, &$selects = null)
 {
     //run the parent method
     parent::filterQuery($query, $selects);
     //if there is no value, return
     if (!$this->getOption('value')) {
         return;
     }
     $query->where($this->getOption('foreign_key'), '=', $this->getOption('value'));
 }
 /**
  * Builds a few basic options
  */
 public function build()
 {
     parent::build();
     $options = $this->suppliedOptions;
     $model = $this->config->getDataModel();
     $relationship = $model->{$options['field_name']}();
     $related_model = $relationship->getRelated();
     $options['table'] = $related_model->getTable();
     $options['column'] = $relationship->getPlainForeignKey();
     $this->suppliedOptions = $options;
 }