Forum: Ruby on Rails associations missing record causes error

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
86a01abd9d77ebfc577b2890623c6170?d=identicon&s=25 bitterbal (Guest)
on 2007-02-25 17:51
(Received via mailing list)

I have 2 models

class Product < ActiveRecord::Base
  belongs_to :supplier

class Supplier < ActiveRecord::Base
  has_many :products

It can happen that a product has record where the supplier_id = 0.
When in my views I list all products and one of the columns has the
product.supplier.description field. This fails because there is no
record where the supplier_id = 0.

The user must set the supplier_id later on in the process but I want
to show the word "UNKNOWN" in the supplier.description while the is stil zero.

I cannot make a record in the database with supplier_id = 0 :-(

any ideas ?

This topic is locked and can not be replied to.