Ich habe ein Fotomodell, für das es Fotos aber in einem Bucket-Modell sein können. Das Bucket-Modell ist eine Unterklasse eines Facet-Modells.Rails 5 beinhaltet eifrig
class Photo < ActiveRecord::Base
has_many :facets
has_one :bucket
end
class Facet < ApplicationRecord
# validates_uniqueness_of :user, :scope => :photo_id
belongs_to :photo
belongs_to :user
end
class Bucket < Facet
belongs_to :photo
belongs_to :user
validates :user_id, uniqueness: true
end
Wenn ich ein Foto zu holen, die in den heißen Stein ist, umfassen die Verwendung von I die Photo-Attribute + die Bucket-Attribute zu erhalten erwarten würde. Aber ich habe nur die Foto-Attribute, verwende ich sind wie folgt aus:
Photo.includes(:facets).find(7)
Die Facet Tabelle:
create_table "facets", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci" do |t|
t.integer "user_id"
t.integer "photo_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "type"
t.string "comment"
t.integer "tag_id"
t.bigint "photos_id"
t.index ["photos_id"], name: "index_facets_on_photos_id"
t.index ["user_id", "type", "comment", "tag_id"], name: "index_facets_on_user_id_and_type_and_comment_and_tag_id", unique: true
end