Associations missing record causes error

Hi,

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
supplier.id is stil zero.

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

any ideas ?

Jeroen

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs