one to many relationship?

Hi,

Newbie question (i hope)

2 tables (no rails specs)

CREATE TABLE `werelddelen` (
  `id` smallint(2) unsigned NOT NULL auto_increment,
  `naam` varchar(50) default NULL,
  `naam_en` varchar(50) default NULL,
  `zoeknaam` varchar(50) default NULL,
  PRIMARY KEY (`id`),
  KEY `zoeknaam` (`zoeknaam`)
)

CREATE TABLE `landen` (
  `landcode` char(2) NOT NULL default '',
  `naam` varchar(50) NOT NULL,
  `naam_en` varchar(50) NOT NULL,
  `alt_naam` varchar(200) NOT NULL,
  `landafk` char(3) default NULL,
  `land_zoeknaam` varchar(100) NOT NULL default '',
  `werelddeel_id` tinyint(2) unsigned default NULL COMMENT
'wereldelen.id',
  PRIMARY KEY (`landcode`),
  KEY `land_zoeknaam` (`land_zoeknaam`),
  KEY `werelddeel_id` (`werelddeel_id`)
)

How can realize a one to many relationship between this tables.(cannot
change column-names, because this is our central company database)

1)Werelddelen(continents) can have more than 1 land(countries)
2)Land only can have 1 werelddeel(continent)

Grtz..remco

Hi,

Newbie question (i hope)

2 tables (no rails specs)

CREATE TABLE `werelddelen` (
`id` smallint(2) unsigned NOT NULL auto_increment,
`naam` varchar(50) default NULL,
`naam_en` varchar(50) default NULL,
`zoeknaam` varchar(50) default NULL,
PRIMARY KEY (`id`),
KEY `zoeknaam` (`zoeknaam`)
)

CREATE TABLE `landen` (
`landcode` char(2) NOT NULL default '',
`naam` varchar(50) NOT NULL,
`naam_en` varchar(50) NOT NULL,
`alt_naam` varchar(200) NOT NULL,
`landafk` char(3) default NULL,
`land_zoeknaam` varchar(100) NOT NULL default '',
`werelddeel_id` tinyint(2) unsigned default NULL COMMENT
'wereldelen.id',
PRIMARY KEY (`landcode`),
KEY `land_zoeknaam` (`land_zoeknaam`),
KEY `werelddeel_id` (`werelddeel_id`)
)

How can realize a one to many relationship between this tables.(cannot
change column-names, because this is our central company database)

1)Werelddelen(continents) can have more than 1 land(countries)
2)Land only can have 1 werelddeel(continent)

You want a belongs_to and a has_many. You can use the foreign_key
option to tell it to use the werelddeel_id column.

Fred