Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

Foreign Key data type? 20 Apr 2012 18:44 #2092

  • elohim
  • elohim's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 3
  • Thank you received: 0
This is probably really basic but I am having difficulty understanding how to use the Foreign Key data type in the project builder. I have added the foreign key to one of the tables. I keep expecting a way to add the table/field it is linked to in the Foreign table column but I can't seem to figure out how.

Please help.

Please Log in or Create an account to join the conversation.

Re: Foreign Key data type? 20 Apr 2012 23:01 #2094

Hello elohim, and Welcome to J-Cook and the Forum!

Pretty sure I can help you nail this one. :)

Here is a step-by-step in beginners terms:

Let's assume you are going to create 2 Tables. Address and Countries. When entering data into the Address Table using a View Layout Form you don't want to have to type the Country Name every time. You want a List of Country Names to select from instead.

Table 1 - Address
Data Types: Street (String), Town (String), Country (String)

When adding the Data Types for this Table drag the Foreign Key Data Type in for the Country Field, and name it Country Name. (Or whatever really)

This is assuming you wish to pull the Country Names from the next Table, Countries.

Table 2 - Countries
Data Types: Country Name (String)

Now, the important step. This creates the link between the two Tables and creates the Foreign Key.



Done! Now you have successfully created a Foreign Key in the Address Table which links to the Countries Table.

Now when you create a New PAGE (Layout) in the Back End (for example), a Back End Item Layout view, using the Address Table you will be able to click on the Fields Tab on the Left hand side and drag in the Fields from the Address Table (Street, Town) and expand the Country Field and you will see 'Country Name' which you can drag into this layout as well.

I'll leave the rest up to you to experiment with because that's half the fun and enjoyment of J-Cook! Hope that all makes sense. If not we encourage you to keep posting questions because that's what we're here for.

Regards,

Edward.
Passionate Joomla! Developer and J-Cook pro evangelist.
www.jcombuilder.com - we build great Joomla!® Components so you don't have to.
The following user(s) said Thank You: admin

Please Log in or Create an account to join the conversation.

Last edit: by edwardcox. Reason: Edit Image

Re: Foreign Key data type? 22 Apr 2012 10:32 #2099

  • elohim
  • elohim's Avatar Topic Author
  • Offline
  • New Member
  • New Member
  • Posts: 3
  • Thank you received: 0
Thank you! That was very helpful. I did not catch that I could drag the table over to make the connection.

I do see however, that it defaults to connecting to the ID field of the second table. What if the connection between the two tables is something other than the automatically generated ID. For instance I have two tables with an organization id in them that would connect the two. How do I make that connection in the builder?

In my circumstance I have a table of organizations and a table of addresses. I want to connect the organization to multiple addresses by linking the org_id fields.

Please Log in or Create an account to join the conversation.

Re: Foreign Key data type? 22 Apr 2012 18:30 #2101

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
Unfortunatly, it is not possible to change the 'id' name.

Others users are asking for this, and I put it in the list of futures possiblities.

Welcome here, and enjoy the service.
Coding is now a piece of cake

Please Log in or Create an account to join the conversation.

  • Page:
  • 1
Time to create page: 0.324 seconds

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started