views:

17

answers:

1

My app is sending messages to client groups. I send message to each client in a loop.

I'm using 3 ActiveRecord models:

class Message < AbstractBase
  has_and_belongs_to_many :groups
end
class Client < ActiveRecord::Base
  has_and_belongs_to_many :groups
end
class Group < ActiveRecord::Base
  has_and_belongs_to_many :messages
  has_and_belongs_to_many :clients
end

I have to store success info for each client in the loop so in case of error I know where to continue. The idea is to save client's ID in a table X when a message is successfully sent. If I did it with PHP i would control that manually (new db table for storing clients' ids). How would you do that in Ruby on Rails? Do I really need a model for that?

+1  A: 

You can still access the database directly in rails. Go ahead and make a migration and create your new table. There are many ways to run queries directly in rails. You can run them like this:

ActiveRecord::Base.connection.select_one('SELECT COUNT(*) FROM mytable') or ActiveRecord::Base.connection.execute('SELECT * FROM mytable')

Take a look at connection on ActiveRecord::Base for different ways to do it.

If you wanted something else, you could take a look at the Sequel gem.

imightbeinatree at Cloudspace