· 8 years ago · Jun 19, 2018, 09:52 AM
1## DB Table
2CREATE TABLE IF NOT EXISTS `ports` (
3 `id` varchar(36) NOT NULL,
4 `host_id` varchar(36) NOT NULL,
5 `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
6 `port` int(11) NOT NULL,
7 `proto` varchar(16) NOT NULL,
8 `state` varchar(255) DEFAULT NULL
9) ENGINE=InnoDB DEFAULT CHARSET=latin1;
10
11## Ruby Call
12@plist = Ports.find(:all, :joins => [:hosts], :conditions => ["ports.state LIKE ?", state])
13
14## foreign key is "host_id" and not "hosts_id"
15C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/connection_adapters/abstract_adapter.rb:212:in `log': Mysql::Error: Unknown column 'ports.hosts_id' in 'on clause': SELECT `ports`.* FROM `ports` INNER JOIN `hosts` ON `hosts`.id = `ports`.hosts_id WHERE (ports.state LIKE '%') (ActiveRecord::StatementInvalid)