Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Re: [jdgamble] Creating Table with Foreign Key

Quote Reply
Re: [jdgamble] Creating Table with Foreign Key In reply to
Quote:
When you say it handles the foreign keys, do you mean automatically? How does it do so?

When you create a table using Creator,
Code:
$creator->fk(table2 => { foo_fk => "foo" })

it adds the foreign key relations information to the .def file.
Code:
'fk' => {
'demo_Links' => {
'LinkID' => 'ID'
}
},

So, whenever you use
Code:
$DB->table([qw/table1 table2/])

the proper JOIN language is added to the generated SQL, so you can do:

Code:
$db->select()
instead of:
Code:
$db->select({"table1.foo_fk" => \"table2.foo"});

Quote:
Does that mean the creator->fk function is worthless?
Nope. See above.

Quote:
Does it only create foreign keys for links tables (not custom tables for new plugins?)
No, it works for ALL tables created using GT::SQL::Creator (standard and plugins), provided that the fk() function is used when creating the table.

Hope that helps.

Philip
------------------
Limecat is not pleased.
Subject Author Views Date
Thread Creating Table with Foreign Key slg_saravanan 2743 Sep 7, 2006, 12:09 AM
Post Re: [slg_saravanan] Creating Table with Foreign Key
fuzzy logic 2690 Sep 7, 2006, 6:35 PM
Thread Re: [slg_saravanan] Creating Table with Foreign Key
brewt 2677 Sep 7, 2006, 10:32 PM
Thread Re: [brewt] Creating Table with Foreign Key
jdgamble 2631 Sep 8, 2006, 2:13 PM
Thread Re: [jdgamble] Creating Table with Foreign Key
fuzzy logic 2627 Sep 8, 2006, 3:48 PM
Thread Re: [fuzzy logic] Creating Table with Foreign Key
jdgamble 2631 Sep 8, 2006, 8:18 PM
Thread Re: [jdgamble] Creating Table with Foreign Key
fuzzy logic 2605 Sep 8, 2006, 8:56 PM
Post Re: [fuzzy logic] Creating Table with Foreign Key
jdgamble 2625 Sep 8, 2006, 9:08 PM