I have a database setup as follows:
CREATE TABLE `images`(
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(20) NOT NULL,
`description` VARCHAR(255),
PRIMARY KEY (`id`)
) ENGINE=INNODB COMMENT='' ROW_FORMAT=DEFAULT;
CREATE TABLE `images_sizes` (
`image_id` INT(11) UNSIGNED NOT NULL,
`size` VARCHAR(7) NOT NULL,
PRIMARY KEY (`image_id`,`size`),
CONSTRAINT `images_size_image_fk` FOREIGN KEY (`image_id`) REFERENCES `images` (`id`)
) ENGINE=INNODB COMMENT='' ROW_FORMAT=DEFAULT;
CREATE TABLE `advertisers`(
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
`website` VARCHAR(255),
`contact_name` VARCHAR(50) NOT NULL,
`contact_phone` VARCHAR(50) NOT NULL,
`contact_email` VARCHAR(50) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=INNODB COMMENT='' ROW_FORMAT=DEFAULT;
CREATE TABLE `ad_blocks` (
`id` int(11) unsigned NOT NULL auto_increment,
`image_id` int(11) unsigned default NULL,
`title` varchar(25) default NULL,
`text` varchar(70) NOT NULL,
`link_text` varchar(15) default NULL,
`link_href` varchar(100) NOT NULL,
`advertiser_id` int(11) unsigned NOT NULL,
`is_active` tinyint(1) default '0',
PRIMARY KEY (`id`),
KEY `image_id` (`image_id`),
KEY `advertiser_id` (`advertiser_id`),
CONSTRAINT `ad_block_advertiser_fk` FOREIGN KEY (`advertiser_id`) REFERENCES `advertisers` (`id`),
CONSTRAINT `ad_block_image_fk` FOREIGN KEY (`image_id`) REFERENCES `images` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
CREATE TABLE `ad_block_activities` (
`ad_block_id` int(11) unsigned NOT NULL,
`user_name` varchar(32) NOT NULL,
`action` varchar(32) NOT NULL,
`activity_ts` int(11) NOT NULL,
PRIMARY KEY (`ad_block_id`,`activity_ts`),
CONSTRAINT `activity_ad_block_fk` FOREIGN KEY (`ad_block_id`) REFERENCES `ad_blocks` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
When working with an AdBlock object how can I retrieve the associated Image? The fActiveRecord::build method is returning an error (as it should in this case). Do I need to change my design or is there a method I'm not seeing?