⚠ 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

Want to show foreign key of foreign key in dropdown



TechDaddies-Kevin
  • profile picture
  • Member

Posted 04 June 2012 - 14:07 PM

This is an unorthodox question, but here it goes:

I have a table called Programs. Programs has a foreign key called categoryID to the Categories table. I have a table called Campus_Programs. This has a foreign key to the Programs table. In my dropdown for Campus_Programs, I am already successfully showing the Program foreign key, and the value from the categoryID column on the Programs table. But what I want to show is the foreign value for that column.

A diagram might help:

Programs: (id, name, categoryID)
-------------------------------------------
1 | Cosmetology | 1


Categories (id, name)
--------------------------------------------
1 | Associate's Degree

Campus_Programs (id, campusID, programID)
------------------------------------------------------------
1 | 1 | 1



So when I edit Campus Program 1, in the 'ProgramID' dropdown I want to show Cosmetology - Associate's Degree instead of just Cosmetology. Right now I have it displaying Cosmetology - 1 (IE Cosmetology - categoryID) but I need to expand that categoryID to get the related value from the Categories table.

Hopefully Grocery CRUD can allow for this use case.

fieldju
  • profile picture
  • Member

Posted 05 June 2012 - 02:49 AM

what your trying to do is a join and you have to write a custom model for it to work right
http://www.grocerycrud.com/documentation/options_functions/set_model

I never did get it to work for me Good Luck.

TechDaddies-Kevin
  • profile picture
  • Member

Posted 05 June 2012 - 13:22 PM

Yeah - I know how to write the query manually, no problem. But I'm having a heck of a time getting it to work in GC. I haven't looked into writing a custom model (Was hoping it could handle it out of the box) but I will try to tackle it today. Thanks for pointing me in the right direction.