Slide 16
Slide 16 text
1. 🚀 ҠߦઌϞσϧ࡞ɺچˠ৽ͷಉ࣌ॻ͖ࠐΈ
• ҠߦઌͱͳΔதؒςʔϒϧΛ࡞͢Δ
• ৽ΞιγΤʔγϣϯΛɺچΞιγΤʔγϣϯͱผ໊Ͱੜ͢
• after_create ίʔϧόοΫͰɺچΞιγΤʔγϣϯ͕࡞͞ΕͨΒ৽ΞιγΤʔ
γϣϯΛಉ࣌ʹ࡞͢Δ
• ඞཁʹΑͬͯɺߋ৽ɾআ͞ΕΔ߹ରԠ
• 👉 ͜Ε͔ΒՃ͞ΕΔσʔλ৽چͰಉظ͞ΕΔ
class Message < ApplicationRecord
has_many :photos, as: :imageable
has_many :message_photos
has_many :renewed_photos, through: :message_photos,
source: :photo
end
class Photo < ApplicationRecord
belongs_to :imageable, polymorphic: true
has_many :message_photos
has_many :messages, through: :message_photos
after_create :create_message_photos!,
if:
- >
{ imageable.is_a?(Message) }
def create_message_photos!
message_photos.create!(message: imageable)
end
end