I have two classes, Listing and Warranty. A Listing (think of it as a
product) may or may not have a Warranty from a lookup table.
When I want the Warranty.company for a given Listing I want to say the
@listing = Listing.find(4)
@company = @listing.warranty.company
In order to do that I did the following:
class Listing < ActiveRecord::Base
and of course my Listing table has a warranty_id column.
This feels wrong. For one thing, it implies a parent-child relationship
and implies that any Listings with a given Warranty can/should be
deleted when a Warranty is deleted. Secondly, when I do delete a
Warranty, my Listing’s warranty_id still points to the deleted record’s
ID, when it should instead be set to nil.
Is there a more appropriate way to express the relationship between a
class and a lookup table?