I have three tables that has the following structure:
CREATE TABLE `crawled_data` (
`id` int NOT NULL,
`url` longtext,
***OMMITTED***
PRIMARY KEY (`id`)
);
CREATE TABLE `ingredient_frequency` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`url_id` int DEFAULT NULL,
`url` text,
***OMMITTED***
PRIMARY KEY (`id`)
)
CREATE TABLE `url_metadata` (
`id` int unsigned NOT NULL AUTO_INCREMENT,
`url` longtext,
***OMMITTED***
PRIMARY KEY (`id`)
);
I have defined the following active record structure:
class Crawled_Data < ActiveRecord::Base
self.table_name = "crawled_data"
has_many :url_metadatas
end
class Ingredient_Frequency < ActiveRecord::Base
self.table_name = "ingredient_frequency"
belongs_to :url_metadata
end
class Url_Metadata < ActiveRecord::Base
self.table_name = "url_metadata"
has_many :ingredient_frequencies
belongs_to :crawled_data
end
How should I go on joining crawled_data with url_metadata by matching the url columns (which aren't the primary keys in both tables)?
I have looked through the following threads but had no luck because the answers do not really mention how to reference the current table's column (instead only talking about referencing the foreign_key)