Skip to content

Inconsistencies between magic builder methods and magic setter methods #6

Open
@jstruzik

Description

@jstruzik

When creating an AbstractModel via the several builder methods:

$model = new Model(['attribute' => 'value']);

$model = $parent->create_model = ['attribute' => 'value'];

$model = $parent->build_model = ['attribute' => 'value'];

The model expects the attribute to match the column type. Only issue with that is if we have a magic setter for a particular attribute:

public function set_attribute(\DateTime $attribute) {
  $time_stamp = $attribute->getTimestamp();

  // Attribute in DB column expects an int type, not a DateTime
  $this->assign_attribute('attribute', $time_stamp);
}

The magic setter will be called during the magic creation but we get an error no matter what is passed in as the value. This is because if the value passed in is an int, the magic setter expects a DateTime. If the value passed in is a DateTime the mass assignment during the magic creation expects the type to be in parity with the table column (an int).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions