steps
steps

Reputation: 804

CodeIgniter GroceryCrud set_relation same id in multiple tables

In GroceryCrud how do I set_relation using the same Id in diferent tables?

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?

Upvotes: 0

Views: 1460

Answers (1)

Ivan Jovović
Ivan Jovović

Reputation: 5298

If you want to create drop-down list that would render as Field - OtherField instead your Id column, then you can:

Create a view in your DB which would join tables Table1 and Table2, eg:

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:

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

Upvotes: 1

Related Questions