Skip to content

Commit

Permalink
Merge pull request #280 from FrozenNode/dev
Browse files Browse the repository at this point in the history
Merging 4.4.1 into master
  • Loading branch information
janhartigan committed Jul 31, 2013
2 parents a23617b + 488f774 commit 73bfec0
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 11 deletions.
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## Changelog

### 4.4.1

- Bugfix: Removed reliance on MySQL-specific backticks in queries
- Bugfix: New validateArray method in Laravel core Validator class was messing with custom version in Administrator's Validator
- Bugfix: In relationship where clauses, there would be issues with values defined on the pivot table

### 4.4.0
- You can now provide custom actions to a "global_actions" option in model configs. These actions are passed the current filtered query object and can be used to perform table-wide actions.
- There is now a query_filter option for model configs that lets you filter a model's results query before it's constructed
Expand Down
8 changes: 7 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Administrator is a database interface package for the Laravel PHP framework. Adm

- **Author:** Jan Hartigan
- **Website:** [http://frozennode.com](http://frozennode.com)
- **Version:** 4.4.0
- **Version:** 4.4.1

[![Build Status](https://travis-ci.org/FrozenNode/Laravel-Administrator.png?branch=master)](https://travis-ci.org/FrozenNode/Laravel-Administrator)

Expand Down Expand Up @@ -53,6 +53,12 @@ Administrator is released under the MIT License. See the LICENSE file for detail

## Changelog

### 4.4.1

- Bugfix: Removed reliance on MySQL-specific backticks in queries
- Bugfix: New validateArray method in Laravel core Validator class was messing with custom version in Administrator's Validator
- Bugfix: In relationship where clauses, there would be issues with values defined on the pivot table

### 4.4.0
- You can now provide custom actions to a "global_actions" option in model configs. These actions are passed the current filtered query object and can be used to perform table-wide actions.
- There is now a query_filter option for model configs that lets you filter a model's results query before it's constructed
Expand Down
2 changes: 1 addition & 1 deletion src/Frozennode/Administrator/DataTable/Columns/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function filterQuery(&$selects)
{
if ($select = $this->getOption('select'))
{
$selects[] = $this->db->raw($select . ' AS `' . $this->getOption('column_name') . '`');
$selects[] = $this->db->raw($select . ' AS ' . $this->db->getQueryGrammar()->wrap($this->getOption('column_name')));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function filterQuery(&$selects)

$selects[] = $this->db->raw("(SELECT " . $this->getOption('select') . "
FROM " . $from_table." AS " . $field_table . ' ' . $joins . "
WHERE " . $where . ") AS `" . $columnName . "`");
WHERE " . $where . ") AS " . $this->db->getQueryGrammar()->wrap($columnName));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ public function filterQuery(&$selects)
.' LEFT JOIN '.$other_table.' AS '.$other_alias.' ON '.$other_alias.'.'.$other_key.' = '.$int_alias.'.'.$column2;

//grab the existing where clauses that the user may have set on the relationship
$relationshipWheres = $this->getRelationshipWheres($relationship, $other_alias);
$relationshipWheres = $this->getRelationshipWheres($relationship, $other_alias, $int_alias);

$where = $this->tablePrefix . $model->getTable() . '.' . $model->getKeyName() . ' = ' . $int_alias . '.' . $column1
. ($relationshipWheres ? ' AND ' . $relationshipWheres : '');

$selects[] = $this->db->raw("(SELECT " . $this->getOption('select') . "
FROM " . $from_table." AS " . $field_table . ' ' . $joins . "
WHERE " . $where . ") AS `" . $columnName . "`");
WHERE " . $where . ") AS " . $this->db->getQueryGrammar()->wrap($columnName));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function filterQuery(&$selects)

$selects[] = $this->db->raw("(SELECT " . $this->getOption('select') . "
FROM " . $from_table." AS " . $field_table . ' ' . $joins . "
WHERE " . $where . ") AS `" . $columnName . "`");
WHERE " . $where . ") AS " . $this->db->getQueryGrammar()->wrap($columnName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,11 @@ public function getIncludedColumn()
*
* @param Illuminate\Database\Eloquent\Relations\Relation $relationship
* @param string $tableAlias
* @param string $pivotAlias
*
* @return string
*/
public function getRelationshipWheres($relationship, $tableAlias)
public function getRelationshipWheres($relationship, $tableAlias, $pivotAlias = null)
{
//get the query instance
$query = $relationship->getQuery()->getQuery();
Expand All @@ -94,7 +95,17 @@ public function getRelationshipWheres($relationship, $tableAlias)
//iterate over the wheres to properly alias the columns
foreach ($query->wheres as &$where)
{
$where['column'] = $tableAlias . '.' . $where['column'];
//split the $where column on '.' which indicates that the clause is for a pivot table
$split = explode('.', $where['column']);

if (isset($split[1]))
{
$where['column'] = $pivotAlias . '.' . $split[1];
}
else
{
$where['column'] = $tableAlias . '.' . $where['column'];
}
}

$sql = $query->toSql();
Expand Down
2 changes: 1 addition & 1 deletion src/Frozennode/Administrator/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function validateDirectory($attribute, $value, $parameters)
/**
* Validates that an item is an array
*/
public function validateArray($attribute, $value, $parameters)
public function validateArray($attribute, $value)
{
return is_array($value);
}
Expand Down
7 changes: 6 additions & 1 deletion tests/DataTable/Columns/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ public function testBuild()
public function testFilterQueryAddsSelect()
{
$this->column->shouldReceive('getOption')->twice()->andReturn('foo');
$this->db->shouldReceive('raw')->once()->andReturn('foo');
$grammar = m::mock('Illuminate\Database\Query\Grammars');
$grammar->shouldReceive('wrap')->once()->andReturn('');
$this->db->shouldReceive('raw')->once()->andReturn('foo')
->shouldReceive('getQueryGrammar')->once()->andReturn($grammar);
$selects = array();
$this->column->filterQuery($selects);
$this->assertEquals($selects, array('foo'));
Expand All @@ -96,6 +99,8 @@ public function testFilterQueryAddsSelect()
public function testFilterQueryDoesntAddSelect()
{
$this->column->shouldReceive('getOption')->once();
$this->db->shouldReceive('raw')->never()
->shouldReceive('getQueryGrammar')->never();
$selects = array();
$this->column->filterQuery($selects);
$this->assertEquals($selects, array());
Expand Down
5 changes: 4 additions & 1 deletion tests/DataTable/Columns/Relationships/HasOneOrManyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ public function testFilterQuery()
{
$relationship = m::mock(array('getPlainForeignKey' => '', 'getRelated' => m::mock(array('getTable' => 'table'))));
$model = m::mock(array('getTable' => 'table', 'getKeyName' => '', 'method' => $relationship));
$grammar = m::mock('Illuminate\Database\Query\Grammars');
$grammar->shouldReceive('wrap')->once()->andReturn('');
$this->config->shouldReceive('getDataModel')->once()->andReturn($model);
$this->column->shouldReceive('getOption')->times(3)->andReturn('column_name', 'method', 'select')
->shouldReceive('getRelationshipWheres')->once()->andReturn('');
$this->db->shouldReceive('raw')->once()->andReturn('foo');
$this->db->shouldReceive('raw')->once()->andReturn('foo')
->shouldReceive('getQueryGrammar')->once()->andReturn($grammar);
$selects = array();
$this->column->filterQuery($selects);
$this->assertEquals($selects, array('foo'));
Expand Down

0 comments on commit 73bfec0

Please sign in to comment.