Skip to content

Commit

Permalink
Some Minor improvements. (#77)
Browse files Browse the repository at this point in the history
* fix bug in docs.

* allow addFields(['foo','bar']) without associations.

* Validation improvement.

* addCondition('foo', ['a','b']); shouldn't touch default.

* style.
  • Loading branch information
romaninsh authored and DarkSide666 committed Jul 26, 2016
1 parent 109ffac commit 1ea85b2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
6 changes: 3 additions & 3 deletions docs/relations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ keep making your query bigger and bigger::

$invoice->hasMany('Invoice_Line', new Model_Invoice_Line())
->addFields([
['total_vat', ['aggregate'=>'sum']],
['total_net', ['aggregate'=>'sum']],
['total_gross', ['aggregate'=>'sum']],
['total_vat', 'aggregate'=>'sum'],
['total_net', 'aggregate'=>'sum'],
['total_gross', 'aggregate'=>'sum'],
]);


Expand Down
3 changes: 3 additions & 0 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ class Field
*/
public function __construct($defaults = [])
{
if (!is_array($defaults)) {
throw new Exception(['Field requires array for defaults', 'arg' => $defaults]);
}
foreach ($defaults as $key => $val) {
$this->$key = $val;
}
Expand Down
6 changes: 5 additions & 1 deletion src/Field_SQL_One.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public function addField($field, $their_field = null)
public function addFields($fields = [])
{
foreach ($fields as $field => $alias) {
$this->addField($field, $alias);
if (is_numeric($field)) {
$this->addField($alias);
} else {
$this->addField($field, $alias);
}
}

return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,7 @@ public function addCondition($field, $operator = null, $value = null)
if ($operator === '=' || func_num_args() == 2) {
$v = $operator === '=' ? $value : $operator;

if (!is_object($v)) {
if (!is_object($v) && !is_array($v)) {
$f->setAttr('default', $v);
}
}
Expand Down

0 comments on commit 1ea85b2

Please sign in to comment.