我有一個關聯模型。根表是Master_student。其他一切有一個外鍵由一個人的cakephp - 加入表格
1)最後搜索到master_student_ssn
<?php
class MasterStudent extends AppModel {
var $name = 'MasterStudent';
var $primaryKey = 'ssn';
var $displayField = 'SSN';
var $useTable = 'MASTER_STUDENTS';
var $order = array("ssn" => "asc");
var $hasMany = array(
'MasterEmail' => array(
'className' => 'MasterEmail',
'foreignKey' => 'master_student_ssn',
'conditions' => '',
'order' => 'source',
'limit' => '',
'dependent' => true
),
'MasterAddress' => array(
'className' => 'MasterAddress',
'foreignKey' => 'master_student_ssn',
'conditions' => '',
'order' => 'source',
'limit' => '',
'dependent' => true
),
'MasterPhone' => array(
'className' => 'MasterPhone',
'foreignKey' => 'master_student_ssn',
'conditions' => '',
'order' => 'source',
'limit' => '',
'dependent' => true
),
'MasterStudentName' => array(
'className' => 'MasterStudentName',
'foreignKey' => 'master_student_ssn',
'conditions' => '',
'order' => 'Effective_Date desc,source',
'limit' => '',
'dependent' => true
)
);
}
?>
[MASTER_STUDENTS](
[SSN] [int] NOT NULL,
[date_student_added] [datetime] NULL,
CONSTRAINT [PK_MASTER_STUDENT] PRIMARY KEY CLUSTERED
(
[SSN] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
[MASTER_ADDRESSES](
[id] [int] IDENTITY(1,1) NOT NULL,
[master_student_ssn] [int] NOT NULL,
[address1] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[city] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[state] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[zip] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_master_addresses] PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
[MASTER_STUDENT_NAMES](
[ID] [int] IDENTITY(1,1) NOT NULL,
[master_student_ssn] [int] NOT NULL,
[First_Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Middle_Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Last_Name] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_MASTER_STUDENTS_NAMES] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
如何使用蛋糕的find方法,這樣我可以列出所有地址,電話,姓名是亂棍一個人名稱 2)電話號碼
即。我希望Cake的所有數據都可以在這些表上進行連接。
在MasterStudent模型的代碼
$opts = array(
'conditions' => array(
'MasterStudentName.last_name LIKE ' => $searchvalue . '%'
)
);
$this->MasterStudent->recursive = 1;
$data = $this->MasterStudent->find('all', $opts);
與JohnP的辦法生成的查詢是
SELECT [MasterStudent] [SSN] AS [MasterStudent__0],CONVERT(VARCHAR(20),[ MasterStudent]。[date_student_added],20)AS [MasterStudent_ 8],[MasterStudent]。[ssn] AS [MasterStudent _2],[MasterStudent]。[ssn] AS [MasterStudent_ 8] ] AS [MasterStudent _19],[MasterStudent]。[ssn] AS [MasterStudent_ 26],[MasterStudent] [SSN] AS [MasterStudent _36] FROM [MASTER_STUDENTS] AS [MasterStudent] WHERE [MasterStudentName] [LAST_NAME] = '史密斯'
你真的還在使用PHP 4嗎? – 2011-03-18 18:10:19
@Justin,這只是Cake的代碼生成。它確實保持兼容 – JohnP 2011-03-18 18:14:58
我指的是在PHP類聲明中使用'var'。 – 2011-04-28 06:34:46