Created
August 17, 2012 04:31
-
-
Save aalvesjr/3375930 to your computer and use it in GitHub Desktop.
Acessar atributos de objetos usados como Join Tables em relacionamentos N x N (many to many)
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
| # Schema usado nos testes | |
| # | |
| #ActiveRecord::Schema.define(:version => 20120817041434) do | |
| # | |
| # create_table "budgets", :force => true do |t| | |
| # t.string "name" | |
| # t.datetime "created_at", :null => false | |
| # t.datetime "updated_at", :null => false | |
| # end | |
| # | |
| # create_table "providers", :force => true do |t| | |
| # t.string "name" | |
| # t.datetime "created_at", :null => false | |
| # t.datetime "updated_at", :null => false | |
| # end | |
| # | |
| # create_table "solicitations", :force => true do |t| | |
| # t.string "visualized" | |
| # t.integer "provider_id" | |
| # t.integer "budget_id" | |
| # t.datetime "created_at", :null => false | |
| # t.datetime "updated_at", :null => false | |
| # end | |
| #end | |
| class Budget < ActiveRecord::Base | |
| has_many :solicitations | |
| has_many :providers, :through => :solicitations | |
| end | |
| class Solicitation < ActiveRecord::Base | |
| belongs_to :budget | |
| belongs_to :provider | |
| end | |
| class Provider < ActiveRecord::Base | |
| has_many :solicitations | |
| has_many :budgets, :through => :solicitations | |
| end | |
| p = Provider.new | |
| p.budget_ids = [1] | |
| orcamento_um = p.budgets[0] | |
| # Acessando dados de um objeto usado como JoinTable | |
| orcamento_um.solicitations[0].visualized? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment