【发布时间】:2014-05-16 15:04:50
【问题描述】:
在我的项目中,我的数据库中有 2 个实体,即用户和帐户。一个用户有一个帐户。用户表有 account_id 字段作为引用帐户实体的外键。 我正在为用户自动生成一个新帐户。一切都按我的预期创建。但是我如何引用特定用户的帐户。这是我的注册脚本
public function register ($data = null)
{
if ($data != null) {
try {
$user = R::dispense('user');
$user->name = $data['name'];
$user->lastname = $data['last-name'];
$user->username = $data['username'];
$user->password = $data['password'];
$user->email = $data['email'];
$user->city = $data['city'];
$user->country = $data['country'];
//create account for user
$account = R::dispense('account');
$account->account_no = $this->genAccountNumber();
$account->money_sum = 0;
$user->account = $account;
$id = R::store($user);
return $id;
} catch (Exception $e) {
echo $e->getMessage;
}
}
}
如果有任何帮助,将不胜感激
【问题讨论】:
-
参考the manual。
标签: php orm one-to-one relation redbean