Gossamer Forum
Home : Products : Gossamer Links : Discussions :

getting data into new table

Quote Reply
getting data into new table
Hi all,

I want to allow users to tag links by "industry vertical". Because a link can exist in more than one vertical, I've decided to make a new table called verticals that has all the industry ids, and also create a VerticalLink reference table to store cases where one link can have many industries associated with it.

I've made my industry table and can pull it into include_form.html without any problems using a global as follows:


Code:
'get_verticals' => 'sub {

# -------------------------------------------------------------------
# Returns a select box of all industries
#
my $output = "";
my $element_name = \'VertLinks.VerticalID\';
my $db = $DB->table (\'Verticals\');
my $sth = $db->select ( [\'ID\', \'Name\'] );
while (my $cat = $sth->fetchrow_hashref) {
$output .= "<input name=\'$element_name\' type='checkbox\' value=\'$cat->{ID}\'>$cat->{Name}<br>";
}
return $output;

}',

(this global will need some more work, but it does what I need it to for the time being)

Where I'm having problems is getting the verticalID value into the VertLinks table. I'm using CatLinks as a template and basically duplicated it with all the the correct names. I've resynched the databases and when I add a new record, I don't generate any error. But of course I'm not seeing any new data in the VertLinks table.

Here's my VertLinks.def file:

Code:
{
'ai' => '',
'cols' => {
'LinkID' => {
'default' => '0',
'form_size' => '10',
'form_type' => 'TEXT',
'not_null' => '1',
'pos' => '1',
'type' => 'INT',
'unsigned' => '1',
'zerofill' => '0'
},
'VerticalID' => {
'default' => '0',
'form_size' => '10',
'form_type' => 'TEXT',
'not_null' => '1',
'pos' => '2',
'type' => 'INT',
'unsigned' => '1',
'zerofill' => '0'
}
},
'fk' => {
'cis_Links' => {
'LinkID' => 'ID'
},
'cis_Verticals' => {
'VerticalID' => 'ID'
}
},
'fk_tables' => [],
'index' => {
'lndx' => [
'LinkID'
],
'vertlnndx' => [
'VerticalID'
]
},
'pk' => [],
'subclass' => {
'html' => {},
'table' => {}
},
'unique' => {}
};

This seems like it should be fairly straight forward, but with out any errors, I'm for the time being stumped. Can someone point me in the right direction?

Thanks,
Mike
Quote Reply
Re: [Swaylock] getting data into new table In reply to
I think you'll probably need a plugin for this with a pre_hook on something like add_link.
Quote Reply
Re: [afinlr] getting data into new table In reply to
Yeah, you are right -- it turns out that using the plugin system was the way to deal with this. It took my about 6 hours of solid trial and error to get my head around it and make it work -- but now that I'm up and running I think things will go smoother. As it turns out, I needed to use the user_add_link post hook as that was the only way to access all of the form variables plus the newly added Link ID.

For those who have been frightened of delving into the plugin system -- I highly recommend taking time to try and understand it. It really provides a flexible way to modify LinksSQL without hacking it to pieces (as I always have in the past).

Thanks,
Mike