ruby on rails - delete_all vs destroy_all? -



ruby on rails - delete_all vs destroy_all? -

i looking best approach delete records table. instance, have user user id across many tables. want delete user , every record has id in tables.

u = user.find_by_name('johnboy') u.usage_indexes.destroy_all u.sources.destroy_all u.user_stats.destroy_all u.delete

this works , removes references of user tables, heard destroy_all process heavy, tried delete_all. removes user own user table , id other tables made null, leaves records intact in them. can share right process performing task this?

i see destroy_all calls destroy function on associated objects want confirm right approach.

you right. if want delete user , associated objects -> destroy_all however, if want delete user without suppressing associated objects -> delete_all

according post : rails :dependent => :destroy vs :dependent => :delete_all

destroy / destroy_all: associated objects destroyed alongside object calling destroy method delete / delete_all: associated objects destroyed without calling :destroy method

ruby-on-rails ruby database activerecord

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -