Rails delete table row via migration -


i'm trying delete several rows in table actionable_items via following migration. have debugged , can confirm variables store table row not nil. migration runs successfully, doesn't delete row table. also, know why can debug migration when run rake db:migrate:redo not when run rake db:migrate ?

class removeactionableitems < activerecord::migration   class actionableitem < activerecord::base     attr_accessible :actionable_item, :name, :sequence, :type   end    class menuitemtemp < actionableitem     self.table_name = "actionable_items"   end    class insightreportmenuitemtemp < actionableitem     self.table_name = "actionable_items"   end    def     validation_settings = menuitem.find_by_name("validation settings")     identifier_lookup = menuitem.find_by_name("identifier lookup")     compliance = insightreportmenuitem.find_by_name("compliance")     debugger     validation_settings.destroy! #unless validation_settings.nil?     identifier_lookup.destroy! #unless identifier_lookup.nil?     compliance.destroy! #unless compliance.nil?   end    def down     menuitem.create :name => "validation settings", :type => "menuitem"     menuitem.create :name => "identifier lookup", :type => "menuitem"     insightreportmenuitem.create :name => "compliance", :type => "insightreportmenuitem"   end end 

i tried deleting rails console, once again, pgadmin showing row not deleted.

pmpaware-webapp(development)> compliance = insightreportmenuitem.find_by_name("compliance")   insightreportmenuitem load (3.8ms)  select "actionable_items".* "actionable_items" "actionable_items"."type" in ('insightreportmenuitem') , "actionable_items"."name" = 'compliance' limit 1 => #<insightreportmenuitem id: 264, name: "compliance", actionable_item_id: nil, created_at: "2015-07-23 18:57:25", updated_at: "2015-07-23 18:57:25", actionable_items_count: 0, sequence: nil, type: "insightreportmenuitem"> pmpaware-webapp(development)> compliance.errors => #<activemodel::errors:0x007fc0735ac540 @base=#<insightreportmenuitem id: 264, name: "compliance", actionable_item_id: nil, created_at: "2015-07-23 18:57:25", updated_at: "2015-07-23 18:57:25", actionable_items_count: 0, sequence: nil, type: "insightreportmenuitem">, @messages={}> pmpaware-webapp(development)> compliance.delete    sql (111829.8ms)  delete "actionable_items" "actionable_items"."type" in ('insightreportmenuitem') , "actionable_items"."id" = 264 => #<insightreportmenuitem id: 264, name: "compliance", actionable_item_id: nil, created_at: "2015-07-23 18:57:25", updated_at: "2015-07-23 18:57:25", actionable_items_count: 0, sequence: nil, type: "insightreportmenuitem"> 

found solution

class removeactionableitems < activerecord::migration   class actionableitem < activerecord::base     attr_accessible :actionable_item, :name, :sequence, :type   end    class menuitemtemp < actionableitem     self.table_name = "actionable_items"   end    class insightreportmenuitemtemp < actionableitem     self.table_name = "actionable_items"   end    def     menuitem.delete_all(name: "validation settings") unless menuitem.find_by_name("validation settings").nil?     menuitem.delete_all(name: "identifier lookup")  unless menuitem.find_by_name("identifier lookup").nil?     insightreportmenuitem.delete_all(name: "compliance")  unless insightreportmenuitem.find_by_name("compliance").nil?   end    def down     menuitem.create :name => "validation settings", :type => "menuitem"     menuitem.create :name => "identifier lookup", :type => "menuitem"     insightreportmenuitem.create :name => "compliance", :type => "insightreportmenuitem"   end end 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -