j4mie/idiorm — pull request #183 by mgalang (2014-03-04 08:05:15+00:00)
Title: When using set() with array, second parameter could be used to filter only expected fields

I've modified set() and and _set_orm_property() to use the second parameter to filter only expected fields or known column names using an array of expected field names. This is only used when the first parameter of set() is an array.

I thought this could be useful for example when you serialise a form and pass all its fields as array to set() but want to filter only fields that will be inserted to the database table.

example:

$_POST = array(
'name' => 'some name',
'email' => 'email@email.somedomain',
'_token' => 'sometoken',
'_hidden_field' => 'something'
);

$contact = ORM::for_table('contacts');
$contact->create();
$contact->set($_POST, array('email', 'name'));