⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

set_relation (join) where field names are not same



molahs
  • profile picture
  • Member

Posted 15 September 2013 - 11:01 AM

Hello, complete CI / GCrud newbie here.

 

I am trying to re-create my page which shows fields from 3 different tables. 

The datagrid should allow search on all fields, and i want to have custom columns not from database with custom actions.

for example, one action is "send email" which just calls another php script with values from some of the fields in the datagrid.

 

The problem I have is that the field names in the different tables that have relationship are not the same name.

 

table structure:

New_Orders: id, member_id, order_date, location, location, is_active, is_delete

Members: id, company, email, phone, status, firstname, lastname

New_Orders_Services: id, locationid, service_id, is_delete

 

 

 

My current SQL statement looks like this:

SELECT 
new_orders.id, new_orders.member_id, new_orders.order_date, new_orders.location, new_orders.isactive,
members.company, members.email, members.phone, members.status, CONCAT(members.first_name, " ", members.last_name) AS fullname,
new_orders_services.locationid
FROM new_orders
JOIN members ON members.id = new_orders.member_id
JOIN new_orders_services ON new_orders_services.order_id = new_orders.id
WHERE new_orders_services.service_id = 0 AND new_orders_services.is_delete = 0 AND new_orders.is_delete = 0

My code looks like this:

$crud->set_table('new_orders');
$crud->set_subject('Orders');

$crud->required_fields('id','member_id','order_date','location','isactive');
$crud->set_relation('member_id','members','{company} {email} {phone} {status} {fullname} ( {first_name} {last_name} )');

My question is: how do i tell Grocery CRUD to set the relationship between Orders and Members based on orders.member_id and members.id

 

Many thanks in advance.

 


davidoster
  • profile picture
  • Member

Posted 16 September 2013 - 05:56 AM

Hello and welcome to the forums [member=molahs].

Currently Grocery CRUD doesn't support something like this, as I am aware of, out of the box.

You either need to override (extend the library) and possibly the model along with it or program it yourself via a custom model (not an one that overrides the GC model, a new one) and use this model for more complicated situations like yours.

 

I prefer the later to be honest. If you search on the forums you will find ways of doing either or.

Ask again if you're stuck.


molahs
  • profile picture
  • Member

Posted 16 September 2013 - 09:05 AM

David, thanks for the reply. I will look up how to create custom models. 

 

Is there a way to pass a sql query to grocerycrud to be executed and displayed in a grid format? could you point me in the right direction?

 

I will be using this mainly as an on screen reporting / take action tool. (view info)

Maybe there is something else like or similar to grocerycrud that can achieve what i want?


davidoster
  • profile picture
  • Member

Posted 16 September 2013 - 11:40 AM

For a start you might want to look here, http://www.grocerycrud.com/documentation/options_functions/set_model