Singular method for has_many associations

This is my first feature suggestion here. Please be kind and patient with me. It’s not a very high impact feature.In fact it may seem like a very trivial thing to many.

Do you all think it would be worth it to add a singular method for a has_many association? For example, a user model has_many posts. And we already have user.posts, but what if the has_many association also defines a singular method to get the first association from has_many? Like

Let me try to give an example which may be more appropriate. I’m working on a project which has an order model. An order has many packing_lists. In 99.9% cases an order only has one packing_list. I always end up doing packing_list = order.packing_lists.first.

So I was wondering if this is something others may also find useful. To have a singular method order.packing_list which just returns order.packing_lists.first. I thought about discarding this post thinking how foolish this feature request may sound, but I’m still posting it just to see how this group operates and reacts.

I believe you can do this with has_one.

1 Like