Pluralized model name (UserS.all, have you been there?)

Heck - its May of WTFs, one such moment coming up regularly is:

WTF, I pluralized the Model class name again!

This happens especially when I want to access a buch of the resources, e.g. Stuff.all, less ogten when I go for a single (Though.first, …, Idea.find(rand 100)) or a filtered set (Skill.where(last_time_accessed: $long_time.ago)).

I don’t believe softening things up is an inheritenly good idea (i.e. allowing both pluralized and singular forms) - but does that happen to you guys regularly, too? I believe I have seen this “mistake” in very a recent RailsConf videos slide as well.

2 Likes

I always make the mistake in the console when querying multiple elements, just like you describe.

On the other hand, I cannot think of a way to fix this without lowering the clarity of our code.

This might be an opportunity to lean harder on did_you_mean.

2 Likes

I also do not feel the competences or clarity to make a decision or change regarding that, its just a "WTF why does that happen even if … " for me.

Changing defaults after 10 years might be something that one doesnt want to “try” but has to be sure that its a sane decision.

But thinking lightly about it, maybe it would have been a good convention (although probably breaking the original AR pattern), to have the model name singular (User), but all query-related stuff plural (Users.first, Users.all, Users.where), actually somewhat more than a repository-approach. But again - this would need some brainpower and deeper thinking about.

Ya, for newcomers that might be helpful. I just need to see the error and know what happened :slight_smile:

2 Likes