0
Kohana 3.3 ORM부터 시작하여 기존 내부 프로젝트에 적용하려고합니다.Kohana 3.3 ORM 관계
프로젝트가 사용 중이므로 스키마 이름을 변경할 수 없습니다. 현재 스키마 정의는 다음과 같다 :
Table: utente
idUtente VARCHAR PK
nome VARCHAR
// other fields
Table: sessione
idSessione SERIAL PK
idUtente VARCHAR (FK to utente.idUtente)
// other fields
Table: ruolo
idRuolo SERIAL PK
nome VARCHAR
//other fields
Table: ruoloutente
idRuolo PK (FK to ruolo.idRuolo)
idUtente PK (FK to utente.idUtente)
scadenza DATETIME
// other fields
지금 내가 모델로 사용자 정의 테이블 이름 및 사용자 정의 기본 키 이름을 정의하고 내가 ORM :: 공장 ('Utente', '마르코')를 사용하는 경우; (또는 다른 모델) 모든 것이 잘 될 것입니다.
class Model_Utente extends ORM {
protected $_table_name ='utente';
protected $_primary_key ='idUtente';
protected $_has_many =
array(
'ruoli' => array(
'model' => 'Ruolo',
'far_key' => 'idRuolo',
'foreign_key' => 'idUtente',
'through' => 'ruoloutente',
),
'sessioni' => array(
'model' => 'Sessione',
'far_key' => 'idSessione',
'foreign_key' => 'idUtente',
),
);
// class logic here
}
class Model_Ruolo extends ORM {
protected $_table_name ='ruolo';
protected $_primary_key ='idRuolo';
protected $_has_many =
array(
'utenti' => array(
'model' => 'Utente',
'far_key' => 'idUtente',
'foreign_key' => 'idRuolo',
'through' => 'ruoloutente',
),
);
// class logic here
}
class Model_Sessione extends ORM {
protected $_table_name ='sessione';
protected $_primary_key ='idSessione';
protected $_belongs_to =
array(
'utente' => array(
'model' => 'Utente',
'far_key' => 'idUtente',
'foreign_key' => 'idUtente',
),
);
// class logic here
}
지금 Utente의 인스턴스에서 내가
$this->ruoli->find_all()및
$this->sessioni->find_all()실행하지만 난 모두 빈 모델을 얻을 .. 생성 된 쿼리는 모두 발견에 올바른 쿼리 SQL에서 직접 실행은 ruoli 및이 4 개 결과를 반환 sessioni에 결과 ..
모든 클래스는 동일한 이름을 가지고 있습니다. –
아니요, 복사 및 붙여 넣기 오류가 수정되었습니다. 죄송합니다 :) –
내가 가서 대답하기 전에 모델 간의 잘못된 관계를 선택했다고 생각합니다. 당신은 나를 위해 이것을 분명히 할 수 있습니까? 사용자가 단일 역할과 단일 세션을 가질 수 있다고 가정합니다. 맞습니까? –