ActiveRecord :has_many associations and === operator?

Post.first. Comments is a delegator. It does not give you back an Array directly, but if you do anything with it, it turns into one.

This is useful because it lets you do stuff like.

Up vote 2 down vote favorite share g+ share fb share tw.

Class Post Array Array === Post.first. Comments => false Array === 1 => true ruby-on-rails ruby activerecord operator-overloading link|improve this question asked Jun 15 '10 at 20:47Jakub17911 71% accept rate.

Post.first. Comments is a delegator. It does not give you back an Array directly, but if you do anything with it, it turns into one.

This is useful because it lets you do stuff like Post.first.comments. All(:conditions => {:author_name => 'RJH'}) without having to inject those methods into the array object, or extending the Array class.

OK, thanks. But is there a way how can I actually find out what class is Post.first. Comments if even #class method is delegated?

– Jakub Jun 16 '10 at 15:52 1 you might find this bit of the rails source interesting: github.com/rails/rails/blob/2-3-stable/a... – BaroqueBobcat Jun 16 '10 at 18:13 OK, thanks a lot! Just for those who might stumble upon this thread, quote from the docs: "As a corner case, it even removes the +class+ method and that's why you get 'blog.posts. Class # => Array' though the object behind blog.

Posts is not an Array, but an ActiveRecord::Associations::HasManyAssociation. – Jakub Jun 18 '10 at 9:48.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions