Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant get same columns nae from 2 tables #461

Open
mflash123 opened this issue Oct 14, 2018 · 9 comments
Open

Cant get same columns nae from 2 tables #461

mflash123 opened this issue Oct 14, 2018 · 9 comments

Comments

@mflash123
Copy link

$crud->set_table('ci_company');
$crud->columns('name');
$crud->set_relation('tarif_id','ci_tarif','name');

I have same name column "Name" in 2 tables: ci_company and ci_tarif. Example show me only name from ci_company. How can I get name from ci_tarif?

@bvrignaud
Copy link
Contributor

Can you try this :

$crud->columns('ci_company.name');

I don't remember if this works.

You may find more help here : https://www.grocerycrud.com/forums/

@mflash123
Copy link
Author

No, it doesnt work.

$crud->set_table('ci_company');
$crud->columns('ci_company.name','ci_tarif.name');
$crud->set_relation('tarif_id','ci_tarif','name');

There is sql query:

SELECT `ci_company`.*, j632c92be.name AS s632c92be, `ci_company`.name AS 'ci_company.name'
FROM `ci_company`
LEFT JOIN `ci_tarif` as `j632c92be` ON `j632c92be`.`id` = `ci_company`.`tarif_id`
 LIMIT 10 

As you can see, he doesnt take NAME column from select from ci_tarif table.

Can you try this :

$crud->columns('ci_company.name');

I don't remember if this works.

You may find more help here : https://www.grocerycrud.com/forums/

@portapipe
Copy link
Contributor

Mmmm... I’ve added the join() function in my branch (It has more stuff but not as beautiful as Scombourdis ;) )
Try it and it will add you the power of the join functionality.

@bvrignaud
Copy link
Contributor

I think tat the easiest way is to prefix your fields names in your database.
That's watt I did in each of my project where I use GroceryCRUD.
ex:

TABLE ci_company
 cin_name,
...
TABLE ci_tarif
 cit_name,

@mflash123
Copy link
Author

Mmmm... I’ve added the join() function in my branch (It has more stuff but not as beautiful as Scombourdis ;) )
Try it and it will add you the power of the join functionality.

I cloned your branch but same problem still exist

@portapipe
Copy link
Contributor

portapipe commented Oct 15, 2018

Did you use the join() function? If have to use the complete name: table.fieldname

Ex.
$crud->join(“client”,”client.id = event.client.id”);
$crud->select(“client.name as ‘client.name’, client.surname as ‘client.surname’, event_name”);

$crud->where(“client.name”,”portapipe”);

Then you’ll have the complete table.fieldname name for each join except for the main table that you have to use with regular name without table name.
I’m using this trick in a working project, and I’ve made a page with this code today.
Enjoy :)

@mflash123
Copy link
Author

mflash123 commented Oct 16, 2018

God damn such unfriendly CRUD..Now it works. But add_fields doesnt show same name fields with exist value.
Thats funny because I decided use CRUD to make smart tickets. And It becames long tickets.

Did you use the join() function? If have to use the complete name: table.fieldname

Ex.
$crud->join(“client”,”client.id = event.client.id”);
$crud->select(“client.name as ‘client.name’, client.surname as ‘client.surname’, event_name”);

Then you’ll have the complete table.fieldname name for each join except for the main table that you have to use with regular name without table name.
I’m using this trick in a working project, and I’ve made a page with this code today.
Enjoy :)

@bvrignaud
Copy link
Contributor

Try this:

$this->crud->display_as('client.name', 'Client');

@mflash123
Copy link
Author

mflash123 commented Oct 16, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants