While reading the documentation of ActiveRecord::Associations, there are many useful methods, that I didn´t know about it.
But one came to me as quite useful,
inverse_of. This method allow us to work with associations that haven`t been save yet, so it will work with the memory.
This will optimise our object loading.
I will so you with some example.
Class Post < ActiveRecord::Base has_many :comments, inverse_of :post end Class Comment < ActiveRecord::Base belongs_to :post, inverse_of :comments end