Strange behaviour with ActiveRecord has_many collections, Rails 4 compared to Rails 3

Hi All,

I have been told to post discussion based topic on here instead of the
GitHub Issues.

I thought this ‘could’ be a bug, but just need some clarification
The issue I posted is here,
does anyone have any thoughts?


Thanks a lot.

On Monday, October 21, 2013 11:28:22 AM UTC+1, Neil Williams wrote:


Thanks a lot.

To be honest it feels to me like what you were using just happened to
by accident, because by default method_missing on the association sets
up a
scope and calls the method on the class. If this was indeed accidental
behaviour then the change could well be the side effect of another
Using new in this way isn’t something I’ve come across in quite a few
of using rails.


Hi Fred,

Thanks for your reply.

“Using new in this way isn’t something I’ve come across in quite a few
years of using rails.”
How would you initialise a new Task object given you have the @story
instance available to you?

@task = => ?

If the above, I really don’t see the point of the new and build methods
a has_many association…

For a has_one association, I would be able to do:
@task = @story.build_task

So it makes no sense, that @task = doesn’t do the
thing… As ‘build’ seems to just be an alias of ‘new’.


On Monday, October 21, 2013 4:37:22 PM UTC+1, Neil Williams wrote:

I’ve always done…)

The fact that this adds the built instance to the in memory collection
never been a problem for me


Hi Fred,

Thanks for this.

yes I can understand why it has never been a problem. It won’t be too
of a problem for us either, as the collection variable e.g. @tasks,
normally be filtered with .where() or be ordered with .order(),
they would be different instances. But I logged it as a bug, because it
just doesn’t seem right.

I can’t think of any reason why one would want the built instance added
the in memory collection…

Anyway, I think I’ve been a bit cheeky on the Github issue, not sure if
going to get another response!

Thanks for your reply though.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs