同期を維持したい2つのモデルの属性があります。
1.9.3p194 :009 > p
=> #<Product id: 19, name: "Long Sleeve Blue", description: "<p>\tLong Sleeve Blue Flannel shirt comes in all siz...", price: 49.99, vendor_id: 12, created_at: "2012-12-15 23:35:05", updated_at: "2013-01-24 19:11:18", image: "shirt.png", sku: "ABC10034">
1.9.3p194 :010 > p.piggybak_sellable
=> #<Piggybak::Sellable id: 1, sku: "AR4590", description: "Blue Shirt", price: #<BigDecimal:7fa97cd63ff8,'0.2499E2',18(45)>, quantity: 100, item_id: 19, item_type: "Product", active: true, unlimited_inventory: false>
それらの両方は、類似しているいくつかの属性を共有しています。
私は作成の側面を下に持っています-新しいレコードが作成されたら、単に。を実行しafter_create
ます。
問題はレコードの更新にあります。
を呼び出して、によって呼び出されたメソッドでafter_save
を実行すると、無限ループが開始され、アプリがクラッシュします。update_attributes
after_save
多くの列を更新したいので、どうすればそれを達成できますか?
1つの解決策は使用することですupdate_column
が、それは1つの列で機能します。
考え?