Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Models in Rails are implicit, is this an annoying thing?

Considering models in Rails:

class Organization < ActiveRecord::Base  
    belongs_to :OrgType  
end    

Does it bother you that models in Rails don't include the fields that made the entity? I know this is done for DRY's sake but you have to check the data base tables schema every time you want to check model's fields.

like image 322
Chiron Avatar asked Aug 07 '10 00:08

Chiron


People also ask

What are models in Rails?

Models are Ruby classes. They talk to the database, store and validate data, perform the business logic and otherwise do the heavy lifting. They're the chubby guy in the back room crunching the numbers. In this case, the model retrieves video 15 from the database.

What are Ruby models?

What are models? In simple terms, models are Ruby classes that can holds value of a single row in a database table. Since they all inherit ActiveRecord::Base through ApplicationRecord class, they are equipped with all the ActiveRecord methods which enables them to interact with the database.


2 Answers

If you prefer a declarative style of ORM model, you might want to check out DataMapper or Sequel, both of which are easy to plug in to Rails 3.

like image 162
Greg Campbell Avatar answered Oct 22 '22 06:10

Greg Campbell


Not annoying for me... ever since I started using the annotate-models gem to automatically add comments to the top of my model files, listing the fields associated with that model.

like image 3
Jeff Avatar answered Oct 22 '22 05:10

Jeff