0
我剛開始使用Phalcon框架。我從來沒有真正使用過一個框架(或者真的是MVC),所以這是一個學習曲線。使用Phalcon和關係插入數據
我已經創建了2個表格:User
和Client
。
客戶端可以有很多User
's,但用戶只能有1 Client
。
我有以下型號:
<?php
class User extends \Phalcon\Mvc\Model
{
public $id;
public $name;
public $email;
public $username;
public $password;
public $active;
public $isAdmin;
public $client;
public function initialize()
{
$this->setConnectionService('gateway-db');
$this->belongsTo("clientId", "Client", "id");
}
}
<?php
class Client extends \Phalcon\Mvc\Model
{
public $id;
public $code;
public $name;
public $active;
public function initialize()
{
$this->setConnectionService('gateway-db');
$this->hasMany("id", "User", "clientId");
}
}
我想創建一個鏈接到現有Client
用下面的代碼的新User
,但是ClientID的領域是NULL
,而不是鏈接。
$client = Client::findFirstByCode("DEM");
$user = new User();
$user->email = "[email protected]";
$user->is_admin = 1;
$user->username = "lock";
$user->active = 1;
$user->name = "Lachlan";
$user->password = $this->security->hash("password");
$user->client = $client;
我能做什麼錯?