What Changed in Rails v2.3.6 – finally we got inverse_of

RubyOnRails 15 八月 2010 | View Comments

In this commit we found we big improvement.

They add :inverse_of for active_record association

What is that used for?

Here is the example from commit message

class Man < ActiveRecord::Base
  has_one :face, :inverse_of => :man
end

class Face < ActiveRecord::Base
  belongs_to :man, :inverse_of => :face
end

m = Man.first
f = m.face

If we don’t have :inverse_of, f.man will be different object, not m@ object and what's more active_record will fire another sql query if you can @f.man.

After we add :inverse_of option, @ m == f.man , and @f.man will not fire a sql query.

But now :inverse_of only works for has_one, has_many. It also supplies inverse support for belongs_to
associations where the inverse is a has_one and it’s not a polymorphic.

I think DataMapper need change their website why DataMapper. Active Record has Identity Map now

Thanks h-lame for giving us this very useful feature which also have sufficient test.


Tagged in , , ,

What Changed in Rails v2.3.6 – redirect_to with flash

RubyOnRails 15 八月 2010 | View Comments

In this commit rails team improved redirect_to method, we can passing flash option directly.

# ... in an action

#old style
flash[:notice] = "Pay attention to the road"
redirect_to post_url(@post)

#new way
redirect_to post_url(@post), :notice => "Pay attention to the road"
They also add some convenient methods for flash object. Now you can get/set flash object in view by alert,alert=(message),notice,notice=(message)


Tagged in , , ,

What Changed in Rails v2.3.6 – Add Column With Positioning

RubyOnRails 31 七月 2010 | View Comments

In this commit Rails add a new feature that we can specify what’s the postillion to add a column.

# In migration

# add column to in first position
add_column :testings, :new_col, :integer, :first => true

# add column after another column
add_column :testings, :new_col, :integer, :after => "column_a"

# change a column with position
change_column :testings, :second, :integer, :first => true
change_column :testings, :second, :integer, :after => "column_c"

About how column position affect performance, you can see this blog post

Thanks bmarini commit this feature, also thanks jeremy reviewed this commit.



Tagged in ,

Ads Plugin created by Jake Ruston's Wordpress Plugins - Powered by and football database.