SORU
4 NİSAN 2011, PAZARTESİ


nasıl başvurular polimorfik yapmak için geçiş oluşturmak için

Ürünler bir masa var ve bir sütun eklemek istiyorum:

t.references :imageable, :polymorphic => true

Yaparak bu geçiş oluşturmak için çalışıyordum

$ rails generate migration AddImageableToProducts imageable:references:polymorphic

ama belli ki yanlış yapıyorum. Kimseye herhangi bir tavsiyede bulunabilir mi? Teşekkürler

Elle geçiş ürettikten sonra koymak için çalıştığımda, şöyle yaptım:

class AddImageableToProducts < ActiveRecord::Migration
  def self.up
    add_column :products, :imageable, :references, :polymorphic => true
  end

  def self.down
    remove_column :products, :imageable
  end
end

ve hala işe yaramadı

CEVAP
4 NİSAN 2011, PAZARTESİ


Bildiğim kadarıyla, yerleşik polimorfik dernekler için jeneratör yok. Boş bir geçiş oluşturmak ve el ihtiyaçlarınıza göre değiştirin.

Güncelleme: Değiştiriyorsun belirtmek gerekir. 8* *göre:

class AddImageableToProducts < ActiveRecord::Migration
  def up
    change_table :products do |t|
      t.references :imageable, :polymorphic => true
    end
  end

  def down
    change_table :products do |t|
      t.remove_references :imageable, :polymorphic => true
    end
  end
end

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • captainpuppys2000

    captainpuppy

    20 HAZİRAN 2013
  • rtisticsdev

    rtisticsdev

    31 Mayıs 2012
  • UKF Dubstep

    UKF Dubstep

    29 NİSAN 2009