vendredi 22 juillet 2016

Rails 3 joins table and model naming conventions

I am running Ruby 2.1.9 and Rails 3.2.17.

First off, in Rails I always made the assumption that models should almost always be singular. I have seen model names like product_categories_product. This is fine and in habtm situation where you want a model to work with the relationship I have seen instructions_products. Which in Rails sorta may make sense, but I would rather name the model instruction_product. That was associated with a joins table named instructions_products.

In fact I was so frustrated I started looking at how rails names things and this happened? So clearly its an ok name for the model and would correspond to the correct table name. But what is more approriate?

ActiveModel::Naming.singular(InstructionsProducts)

returns instructions_products

Edited: The heart of the question is why is InstructionsProducts a valid model name in rails and why does my example above resolve to the singular 'instructions_products'. This seems odd considering the rails convention is to keep model names singular.

Aucun commentaire:

Enregistrer un commentaire