vendredi 4 septembre 2015

wrong number of arguments (1 for 2..3) for Active Record postgresql query (Rails 4/postgresql 9.4)

When creating a model Deal, I use an after_create to create prizes on the DealPrize table.

Deal and DealPrize have a belong to/has_many relations: a Deal has many Deal prizes and a Dealprize belongs to a Deal.

It works like this: inside Deal, I have a column 'prize-number' and I use an after_create so that evetytime the amdin creates a new deal, the app takes this prize_number column, and create this volume of prizes (inserting as many rows as necessary) inside the DealPrize table.

model deals.rb

CONNEXION = ActiveRecord::Base.connection

def create_prizes
  Deal.transaction do  
    self.1200000.times do |i| 
      st = CONNEXION.raw_connection.prepare("INSERT INTO deal_prizes (deal_id, created_at, updated_at) values (?, ?, ?)")
      st.execute(self.id, Time.now, Time.now)
      st.close
    end
  end
end

Getting error:

wrong number of arguments (1 for 2..3) 

Source- I arrived to this thanks to Dimakura on question ERROR: missing FROM-clause entry for table "self" (Rails 4 Active Record transaction, postgresql 9.4))

Aucun commentaire:

Enregistrer un commentaire