[英]CodeIgniter GroceryCrud set_relation same id in multiple tables
在GroceryCrud中,如何在不同的表中使用相同的ID進行set_relation?
我想做這樣的事情:
$this->grocery_crud->set_relation('Id','Table1','Field');
$this->grocery_crud->set_relation('Id','Table2','OtherField');
但是,當我這樣做時,它僅適用於最后一個值,並且我無法自定義標簽。 如何在不同的表中使用多個關系來實現此目標?
如果要創建一個下拉列表,將其顯示為“ Field - OtherField
而不是您的“ Id
列,則可以:
在數據庫中創建一個將表Table1和Table2連接起來的視圖,例如:
CREATE VIEW Table1_Table2 AS
SELECT Table1.Id, Table1.Field, Table2.OtherField
FROM
Table1 inner join Table2 on Table1.Id = Table2.Id
然后在您的GroceryCRUD應用程序中包含該視圖:
$this->grocery_crud->set_relation('Id', 'Table1_Table2', '{Field} - {OtherField}');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.