Database schema to store AND, OR relation, association

Posted by user455387 on Stack Overflow See other posts from Stack Overflow or by user455387
Published on 2010-12-09T20:38:09Z Indexed on 2010/12/27 12:54 UTC
Read the original article Hit count: 191

Many thanks for your help on this.

In order for an entreprise to get a call for tender it must meet certain requirements.

For the first example the enterprise must have a minimal class 4, and have qualification 2 in sector 5.

Minimal class is always one number.

Qualification can be anything (single, or multiple using AND, OR logical operators)

I have created tables in order to map each number to it's given name. Now I need to store requirements in the database.


  • minimal class 4
  • Sector Qualification 5.2

  • minimal class 2
  • Sector Qualifications 3.9 and 3.10

  • minimal class 3
  • Sector Qualifications 6.1 or 6.3

  • minimal class 1
  • Sector Qualifications (3.1 and 3.2) or 5.6

class Domain < ActiveRecord::Base
  has_many :domain_classes
  has_many :domain_sectors
  has_many :sector_qualifications, :through => :domain_sectors
end

class DomainClass < ActiveRecord::Base
  belongs_to :domain
end

class DomainSector < ActiveRecord::Base
  belongs_to :domain
  has_many :sector_qualifications
end

class SectorQualification < ActiveRecord::Base
  belongs_to :domain_sector
end

  create_table "domains", :force => true do |t|
    t.string "name"
  end

  create_table "domain_classes", :force => true do |t|
    t.integer "number"
    t.integer "domain_id"
  end

  create_table "domain_sectors", :force => true do |t|
    t.string  "name"
    t.integer "number"
    t.integer "domain_id"
  end

  create_table "sector_qualifications", :force => true do |t|
    t.string  "name"
    t.integer "number"
    t.integer "domain_sector_id"
  end

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about database-design