Active Record’s << or push or concat method

Active Record’s << or push or concat method – Introduction

You have used it over and over again but yet there are some gotchas you have to keep in mind when you are using ActiveRecord’s << method of a has_may association.

I was always wondering how ActiveRecord handles the situations where you add a new object in a collection (via of course the << method) and the owner is also new, does it saves the object before adding it to the collection or waits for the owner to get saved and then saves the unsaved objects to the DB? This is one of the questions that are gonna get answered in the following post.

Continue reading

Rails console and ActiveRecord SQL queries – Rails quick tips

Rails console and ActiveRecord logger – Rails 3

Well, there are many many times (in fact always :P) that you want active record sql queries to log into STDOUT and especially when you are working in the rails console. I didn’t know how to do this and after a while of Google searching I stumbled upon this command that you type every time you open the rails console:

Continue reading