search for: destroy_all

Displaying 20 results from an estimated 46 matches for "destroy_all".

2006 Nov 04
0
Model.delete_all vs Model.destroy_all in a habtm
Hi there I have an habtm association between 2 Models. I regularly have to truncate the table on one side of the relationship and repopulate the table with a fresh csv file. I notice that f I do Model.delete_all, none of the records in my habtm join table get deleted, whereas if I use destroy_all they do. However, the overhead of using destroy_all is too great. For the amount of records I have to deal with, destroy_all is very processor and time intensive. How best to quickly truncate one side of the habtm relationship *and* the intermediate join table? I suppose I can drop to connection...
2010 Nov 24
0
Surprise in (delete_all | clear | destroy_all) on association
...lters` SET `updated_at` = ''2010-11-24 09:28:03'' WHERE (`task_filters`.`id` = 1) That is nightmare, I expect delete_all to be fast sql query, but instead I have: * all associated objects loaded * each object was destroyed, with many callbacks and DELETE queries delete_all, clear, destroy_all respect :dependent option, but why ? If association hasn''t :dependent option, then delete_all is duplicate of clear if association has :dependent=> :destroy option, then delete_all, clear are duplicates of destroy_all delete_all work fine on relation so, TaskFilter.first.qualifiers.sco...
2008 Dec 19
3
Delete All action
Hi, What is the best way to delete all members of a model? For example I have a tasks model and want to put a link in that will delete all tasks at once. Something like, @tasks = Task.all @tasks.each { |task| task.destroy } Do I need another action for this, and what should the link to it be? cheers, DAZ --~--~---------~--~----~------------~-------~--~----~ You received this message because
2006 Jan 25
11
Executing Ruby code that is inside a string
I would like to put Ruby code inside a string, between <%= %> tags, and have the code inside the tags executed when the string is displayed. Is this possible? -- Posted via http://www.ruby-forum.com/.
2006 Jul 23
8
destroy vs delete
what is the difference between destroy and delete in AR I am not sure what they mean by "Destroys the record with the given id by instantiating the object and calling destroy<http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000866>(all the callbacks are the triggered). If an array of ids is provided, all of them are destroyed." in
2006 Jul 31
9
Problems with ever-increasing ID value
I have a script that I am using to populate a database from a CSV file: RAILS_ENV = ''development'' require File.dirname(__FILE__) + ''/../../config/environment'' require ''csv'' # Destroy existing data Residence.destroy_all # IMPORT DATA FROM apartments.csv db_file = "#{RAILS_ROOT}/db/apartments.csv" CSV.open(db_file, "r", ''|'') do |row| r = Residence.new r.name = row[0] r.number = row[1] r.street = row[2] r.zip = row[3] r.save end When I run this script it correct...
2007 Sep 07
6
ActiveRecord::Base#update_all expected behaviour
Hi I noticed that if in my code I use the following: Photo.update_all("title = ''Ruby rocks'' ", "id IN (#{@photo_ids})") All my objects are properly updated but none of the filters/callbacks are triggered. Is that what''s expected? I have a before_update filter set on the Photo class and it gets totally ignored, I guess the only way to solve this
2007 Nov 15
2
Trouble using should_receive
I have this code trying to ensure my reset method works. I want to make sure all the participants have their destroy method called. # in my spec for Room r = Room.new(:name => ''bob'') r.save p = Participant.new(:login => ''a'', :password => ''b'', :password_confirmation => ''b'') p.room = r
2005 Dec 08
2
Confusing lock problem in rails
...nd..(ind + 220)] docs << doc end [count, docs] end def mark_as_viewed(user_id) # user = self.users.find(user_id) end def self.delete_old @p = Pref.find_by_setting(''autodelete'') if @p and @p.value.to_i > 0 val = @p.value.to_i destroy_all(["found_on <= DATE_SUB(CURDATE(), INTERVAL ? DAY)", val]) end end def self.delete_before(params) date = sprintf("%04d-%02d-%02d", params[:foundon][:year], params[:foundon][:month], params[:...
2005 Dec 15
8
How to ensure deletes cascade to associated models?
...have the following models: class Resume belongs_to :resume_assignments end class User belongs_to :resume_assignments end class ResumeAssignment has_one :resume has_one :user end When I delete a resume, I want to make sure that its associated ResumeAssignment gets deleted also. Calling destroy_all to delete some resumes doesn''t seem to do this. Is there an option that will make it do this? Thanks, Carl
2006 Jul 26
7
Delete_all causes a deadlock on MSSQL database ???
...lyser, i can''t do a ''select * from foo'' anymore to see if the record has indeed been deleted, because of the deadlock. Its exactly as though rails has opened a transaction but not committed it. Here''s the funnier rub though, if i replace the delete_all with a destroy_all, i don''t have any problems!!! Anyone know whats going on? Here''s the code def save # scan through the params, looking for any starting with ''reason_'' to save params.each {|key,reason| if ''reason_'' == key[0,7] pc,what...
2006 Jul 10
18
Deleting join association of has_many :through
I''m trying to use has_many :through, since my join model deserves being more than just an intersection table. But when I try to break the association, the break only seems "temporary": Let''s say my two tables are Users and Colors, and the join model is Favorites. user = Users.find(1) user.colors.length >> 2 c = user.colors.first >> #<Color:....>
2010 Mar 26
7
seed data
...r,:fips,:country_id, [ { :name => "Alberta", :abbr => ''AB'',:fips => ''01'', :country_id => 2 }, { :name => "Alaska", :abbr => ''AK'',:fips => ''02'', :country_id => 1 } ]) State.destroy_all State.create(:id => 1,:name => "Alabama", :abbr => ''AL'',:fips => ''01'', :country_id => 1) And now when I do select * from states; I get unexpected result as +-----+------+-----------------------+------+------------+ | id | abbr | n...
2006 Sep 25
1
Clearing ActiveRecord Sessions
Hello all, I am interested in using BackgrounDRb to clear out ActiveRecord based sessions. I have this working, just with a small hitch, here is the code: class ClearSessionsWorker < BackgrounDRb::Rails repeat_every 7.minutes first_run Time.now def do_work(args) Session.destroy_all(["updated_at < ?", 20.minute.ago ]) end end It''s not very complicated and does remove sessions, it''s just that once the job is done, the thread hangs out leaving a connection to my database open. After some time, MySQL complains about having too many open connecti...
2006 Jan 06
3
Getting model class by string
Hello, I have an interessting problem, I''m not sure how to solve :-) I have the name of a model in a variable like this: My model is called Article My var contains "Article" Now - How do I get the model class, so I can call Article.find, Article.new etc ... ? Greetings, Gitte Wange
2006 Jan 23
4
Delete row without th eid field
Hi all, I have a table structure with me not having an id column. When I try to delete the row i get an error ''Unknown column "table.id"''. Can i do the action with any other method than destroy/delete? Or with the same method and any other conditions? Thanks. Sainaba. -- Posted via http://www.ruby-forum.com/.
2005 Nov 22
2
How to delete a set of records
I''m trying to delete a set of records from the database using parameters other than the primary key. Is there a method similar to find_by_sql() that can be used to issue a delete statement like this. Thanks in advance. Shaun -- Posted via http://www.ruby-forum.com/.
2008 Jan 01
2
Testing and has_many Questions
To unit test the models'' functionality, I realized I need to call save. That said, I wondered if save in test causes the model to be stored in the database. If so, what should I do to avoid this problem? Should I just call Model.destroy_all at the end? Second, to test controllers'' functionality, is it possible to set the params and session hash? If not, how do you test controller functionality? Also, many of my models uses has_many and belongs_to. What''s the difference between the following methods: count, size,...
2007 Jul 22
2
Seek brilliant Rails programmer to add one field to acts_as_taggable
...a trail or sequence of events that I can modify. I was hoping I could ''go in the front door'' and simply modify the ''tag_with'' code such as this; module InstanceMethods def tag_with(list, project_id) Tag.transaction do taggings.destroy_all Tag.parse(list).each do |name| if acts_as_taggable_options[:from] send(acts_as_taggable_options[:from]).tags.create(:name => name, :project_id => project_id).on(self) else unless Tag.find_by_name(name) Tag.create(:nam...
2006 Jan 07
3
RailsCron 0.1 plugin
...rd, so you can manipulate it in familiar ways: RailsCron.create( :command => "Object.do_something()", :start => 2.minutes.from_now, :every => 12.hours, # default: 1.day :finish => 2.years.from_now # optional ) RailsCron.destroy_all RailsCron.find_by_command "some_command" Cron, when used with RoR, has the following shortcomings: * Significant startup resources required * Lots of RAM to run simultaneous processes * Hard to start/stop/affect the background processes from within Rails. RailsCron addresses these...