$query = Model_User::query()
->where('id', \Input::json('id'))
->related('contact');
$user = $query->get_one();
$user->username = \Input::json('username');
$user->contact->set(\Input::json('contact'));
$user->save();
Array
(
[id] => 2
[username] => leo
[contact] => Array
(
[locale] => nl_NL
)
)
$query = Model_User::query()
->where('id', \Input::json('id'))
->related('contact');
$user = $query->get_one();
$user->set(\Input::json());
$user->save();
public function put_model($accountId = 0)
{
$query = Model_User::query()
->where('id', \Input::json('id'))
->related('contact');
$user = $query->get_one();
$user->set(\Input::json()); // TODO: y u no work?
// $user->username = \Input::json('username');
// $user->contact->set(\Input::json('contact')); // setting this object does work, but it has no nested objects
$user->save();
return $this->response($user->to_array(), 200);
}
{"id":2,"username":"leo","contact":{"locale":"be_BE"}}
$user->set(array('username' => 'leo'));
$user->set(array('username' => 'leo'));
$user->contact->set(\Input::json('contact'));, which also sets an array.
try {
$user->save();
}
catch(\Exception $e) {}
\Debug::d(\DB::last_query());
SELECT `t0`.`id` AS `t0_c0`, `t0`.`username` AS `t0_c1`, `t0`.`password` AS `t0_c2`, `t1`.`id` AS `t1_c0`, `t1`.`title` AS `t1_c1`, `t1`.`user_id` AS `t1_c2`, `t1`.`locale` AS `t1_c3` FROM (SELECT `t0`.`id`, `t0`.`username`, `t0`.`password` FROM `users` AS `t0` WHERE `t0`.`id` = 2 LIMIT 1) AS `t0` LEFT JOIN `contacts` AS `t1` ON (`t0`.`id` = `t1`.`user_id`)
$data = \Input::json();
unset($data['id']);
$user->set($data); // TODO: y u no work?
$user->save();
"package": {
"name": "fuel/orm",
"type": "fuel-package",
"version": "1.8",
"dist": {
"url": "https://github.com/fuel/orm/archive/1.8/develop.zip",
"type": "zip"
},
"source": {
"url": "https://github.com/fuel/orm.git",
"type": "git",
"reference": "1.8/develop"
}
}
"fuel/orm": "1.8",
Fuel\Core\FuelException [ Error ]:
Invalid Model instance added to relations in this model.
PKGPATH/orm/classes/hasone.php @ line 122
1249: if ($this->_data_relations[$property] instanceof static and is_array($value))
\Debug::dump('orm test: ', $property, $value, $this->_data_relations[$property], $this->_data_relations[$property] instanceof static and is_array($value));
die();
if (($this->_data_relations[$property] instanceof static) and is_array($value))
class Model_Contact extends \Orm\Model
{
protected static $_properties = array(
'id',
'title',
'user_id',
'locale'
);
protected static $_belongs_to = array('user');
}
class Model_User extends \Orm\Model
{
protected static $_properties = array(
'id',
'username',
'password',
);
protected static $_to_array_exclude = array (
'password',
'login_hash' // exclude these columns from being exported
);
protected static $_has_one = array(
'contact'
);
\Debug::dump('orm test: ', $property, $value, ($this->_data_relations[$property] instanceof static), is_array($value));
PKGPATH/orm/classes/model.php @ line: 1249
Variable #1:
(String): "orm test: " (10 characters)
Variable #2:
(String): "contact" (7 characters)
Variable #3:
(Array, 1 element) ↵
locale (String): "be_BE" (5 characters)
Variable #4:
(Boolean): false
Variable #5:
(Boolean): true
if (is_a($this->_data_relations[$property], __CLASS__) and is_array($value))it works :)
It looks like you're new here. If you want to get involved, click one of these buttons!