Created
July 1, 2011 12:38
-
-
Save Canx/1058457 to your computer and use it in GitHub Desktop.
modelos_1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| lennon = Persona.find_by_nombre("John Lennon") | |
| lennon.grupo = Grupo.find_by_nombre("Ramones") | |
| lennon.save |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Grupo < ActiveRecord::Base | |
| end | |
| class Persona < ActiveRecord::Base | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class AddGrupoIdToPersona < ActiveRecord::Migration | |
| def change | |
| add_column :personas, :grupo_id, :integer | |
| add_index :personas, :grupo_id | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CreateGrupos < ActiveRecord::Migration | |
| def change | |
| create_table :grupos do |t| | |
| t.string :nombre | |
| t.timestamps | |
| end | |
| end | |
| end | |
| class CreatePersonas < ActiveRecord::Migration | |
| def change | |
| create_table :personas do |t| | |
| t.string :nombre | |
| t.timestamps | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Grupo < ActiveRecord::Base | |
| has_many :personas | |
| end | |
| class Persona < ActiveRecord::Base | |
| belongs_to :grupo | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ActiveRecord::Schema.define(:version => 20110701083257) do | |
| create_table "grupos", :force => true do |t| | |
| t.string "nombre" | |
| t.datetime "created_at" | |
| t.datetime "updated_at" | |
| end | |
| create_table "personas", :force => true do |t| | |
| t.string "nombre" | |
| t.datetime "created_at" | |
| t.datetime "updated_at" | |
| t.integer "grupo_id" | |
| end | |
| add_index "personas", ["grupo_id"], :name => "index_personas_on_grupo_id" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ["Ramones","The Beatles", "The Rolling Stones"].each do |grupo| | |
| Grupo.find_or_create_by_nombre(grupo) | |
| end | |
| joey = Persona.find_or_create_by_nombre('Joey Ramone') | |
| joey.grupo = Grupo.find_by_nombre("Ramones") | |
| joey.save | |
| lennon = Persona.find_or_create_by_nombre('John Lennon') | |
| lennon.grupo = Grupo.find_by_nombre("The Beatles") | |
| lennon.save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment