Active Record Store

I'm having trouble deleting records from the active repository.

I want to delete based on session data:

ActiveRecord::SessionStore::Session.find(:all).each do |s| if s.data[:userid] == 1234 s.destroy end end 

doesn't seem to work, but:

 ActiveRecord::SessionStore::Session.delete_all(["updated_at < ?", 12.hours.ago]) 

seems to work and:

 ActiveRecord::SessionStore::Session.find(:all).each do |s| if s.data[:userid] == 1234 ActiveRecord::SessionStore::Session.delete_all("session_id = ?", s.session_id) end end 

also does not work.

I am running rails 2.3.2, ruby ​​1.8.7.

+4
source share
1 answer

You can simply pass the Active Record method to remove the identifier of the object you want to delete:

 ActiveRecord::SessionStore::Session.delete(1234) 

In another note, be sure to specify the .data attribute in the above example. Session.find (: all) will return an array of session objects, which you then iterate over. A session does not have a userid column unless you have cracked the default session store to add it.

+3
source

Source: https://habr.com/ru/post/1315141/


All Articles