Skip to content

Commit

Permalink
use get_object_vars to export all column properties
Browse files Browse the repository at this point in the history
Fixes: #116
  • Loading branch information
c9s committed Aug 6, 2015
1 parent fb7243c commit b95d1fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
20 changes: 8 additions & 12 deletions src/LazyRecord/Schema/ColumnDeclare.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,27 +202,23 @@ public function validator() {
$this->attributes['validator'] = $args[0];
}


/**
* Export column attributes to an array
*
* @return array
*/
public function export()
{
return array(
'name' => $this->name,
'attributes' => array(
'isa' => $this->isa,
'type' => $this->type,
'primary' => $this->primary,
) + $this->attributes,
'attributes' => array_merge(get_object_vars($this), $this->attributes),
);
}

public function toArray()
{
$attrs = $this->attributes;
$attrs['name'] = $this->name;
$attrs['primary'] = $this->primary;
$attrs['unsigned'] = $this->unsigned;
$attrs['type'] = $this->type;
$attrs['notNull'] = $this->notNull;
return $attrs;
return array_merge(get_object_vars($this),$this->attributes);
}

public function dump()
Expand Down
2 changes: 1 addition & 1 deletion src/LazyRecord/Schema/DeclareSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public function findPrimaryKey()
public function export()
{
$columnArray = array();
foreach( $this->columns as $name => $column ) {
foreach ( $this->columns as $name => $column ) {

// This idea is from:
// http://search.cpan.org/~tsibley/Jifty-DBI-0.75/lib/Jifty/DBI/Schema.pm
Expand Down

0 comments on commit b95d1fc

Please sign in to comment.