E-commerce
class Category < ActiveRecord::Base
has_many :products
end
class Product < ActiveRecord::Base
belongs_to :category
end
class Order < ActiveRecord::Base
has_many :line_items
end
class LineItem < ActiveRecord::Base
belongs_to :product
belongs_to :order
end
Listing 8-3. Role-Based Access Control
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Roles < ActiveRecord::Base
has_and_belongs_to_many :users
has_and_belongs_to_many :permissions
end
CHAPTER 8 ?– ACTIVE RECORD AND THE REAL WORLD 208
class Permission < ActiveRecord::Base
has_and_belongs_to_many :roles
end
Listing 8-4. Surveys / Questionnaires / Quizzes
class Survey < ActiveRecord::Base
has_many :questions
has_many :responses
end
class Question < ActiveRecord::Base
belongs_to :survey
has_many :choices
end
class Choice < ActiveRecord::Base
belongs_to :question
end
class Response < ActiveRecord::Base
belongs_to :survey
has_many :response_choices
end
class ResponseChoice < ActiveRecord::Base
belongs_to :response
belongs_to :question
belongs_to :choice
end
Listing 8-5.
Pages:
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476