简体   繁体   English

CodeIgniter GroceryCrud set_relation在多个表中具有相同的ID

[英]CodeIgniter GroceryCrud set_relation same id in multiple tables

In GroceryCrud how do I set_relation using the same Id in diferent tables? 在GroceryCrud中,如何在不同的表中使用相同的ID进行set_relation?

I want to do something like this: 我想做这样的事情:

$this->grocery_crud->set_relation('Id','Table1','Field');
$this->grocery_crud->set_relation('Id','Table2','OtherField');

But when I do this, it only work for the last value and I can't customize the label. 但是,当我这样做时,它仅适用于最后一个值,并且我无法自定义标签。 How to achieve this goal, using multiple relations in diferent tables? 如何在不同的表中使用多个关系来实现此目标?

If you want to create drop-down list that would render as Field - OtherField instead your Id column, then you can: 如果要创建一个下拉列表,将其显示为“ Field - OtherField而不是您的“ Id列,则可以:

Create a view in your DB which would join tables Table1 and Table2, eg: 在数据库中创建一个将表Table1和Table2连接起来的视图,例如:

CREATE VIEW Table1_Table2 AS
SELECT Table1.Id, Table1.Field, Table2.OtherField
FROM
Table1 inner join Table2 on Table1.Id = Table2.Id

And then include that view in your GroceryCRUD app: 然后在您的GroceryCRUD应用程序中包含该视图:

$this->grocery_crud->set_relation('Id', 'Table1_Table2', '{Field} - {OtherField}');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM