DO
create_table :accessories do |t|
t.references :good, index: true, foreign_key: true
t.references :good, index: true, foreign_key: true
t.timestamps
end
Size: a a a
DO
create_table :accessories do |t|
t.references :good, index: true, foreign_key: true
t.references :good, index: true, foreign_key: true
t.timestamps
end
DO
DO
DO
DO
create_table :accessories do |t|
t.integer :good_id, index: true, foreign_key: true
t.integer :accessory_id, index: true, foreign_key: true
t.timestamps
DO
class Accessory < ApplicationRecord
belongs_to :good, :class_name => 'Good'
belongs_to :accessory, :class_name => 'Good'
end
DO
class Good < ApplicationRecord
has_many :active_relationships , class_name: 'Accessory', foreign_key: 'accessory_id', dependent: :destroy
has_many :passive_relationships , class_name: 'Accessory', foreign_key: 'good_id', dependent: :destroy
has_many :main, through: :active_relationships , source: :good
has_many :depend, through: :passive_relationships , source: :accessory
end
NK
DO
NK
NK
NK
MS
MS
NK
DO

TD
DO
NK