Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistencies between magic builder methods and magic setter methods #6

Open
jstruzik opened this issue Oct 28, 2015 · 0 comments
Open
Labels

Comments

@jstruzik
Copy link
Member

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).

@jstruzik jstruzik added the bug label Oct 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant