title: Rails fields change value
body: <p>I have 3 models <code>Currency</code>, <code>NeuralNetwork</code>, <code>Prediction</code>. Each currency has a neural network associated to it that creates a prediction.</p>
  
  <p>Every time the currency's <code>update</code> method is called, it asks the neural network to generate a new prediction or it uses the prediction already generated. The currency <code>has_one</code> neural network, which <code>has_one</code> prediction.</p>
  
  <p>The currency controller:</p>
  
  <pre><code>def update
      if @currency.update(currency_params)
        prediction = @currency.neural_network.predict
        redirect_to prediction
      end
    end
  </code></pre>
  
  <p>The neural network's model</p>
  
  <pre><code>  def predict
      if(self.prediction == nil)
        #some other code
        (0..29).each do |i|
          #ASS: I'm getting the data for today at the beginning of the day
          self.prediction.exchange_rates &lt;&lt; ExchangeRate.new(last: predicted_rates[i], date: Date.today + i + 1, predicted: true)
        end
      end
      p "there are #{self.prediction.exchange_rates.size} predicted rates"
      self.prediction
    end
  </code></pre>
  
  <p>My problem is that if the controller method is called twice, the following is printed:</p>
  
  <pre><code>    there are 30 predicted rates
      there are 0 predicted rates
  </code></pre>
  
  <p>Why does the field change its value? Why aren't the objects created in the loop remembered?</p>