Ruby on Rails - Models

Model Creation:

Model.new # creates a new empty model
Model.create( :field => 'value', :other_field => 42 )
# creates an object with the passed parameters and saves it
Model.find_or_create_by_field( value )
# searches for a record where "field = value", creates
# a new record if not found
User.find_or_create_by_name_and_email( 'ramjoe', 'ram@example.com')

Model Relations:

There are four ways of associating models. has_one, has_many, belongs_to and has_and_belongs_to_many. Assuming the following four entities: