i'm working on website functions kickstarter political candidates. users can nominate candidates, , can pledge vote candidate, or contribute funds. i'm trying define self join candidate belongs user, want user nominator if they've nominated candidate (like creator creating project on kickstarter). think i've got syntax correct, keep getting errors when try seed database.
my models:
class user < activerecord::base has_many :pledges has_many :candidates, through: :pledges has_many :contributions has_many :candidates, through: :contributions end class candidate < activerecord::base belongs_to :nominator, class_name: "user", foreign_key: "nominator_id" has_many :pledges has_many :users, through: :pledges has_many :contributions has_many :users, through: :contributions end class pledge < activerecord::base belongs_to :user belongs_to :candidate end class contribution < activerecord::base belongs_to :candidate belongs_to :user end below database schema file, minus devise stuff , join tables
activerecord::schema.define(version: 20150714232652) # these extensions must enabled in order support database enable_extension "plpgsql" create_table "candidates", force: :cascade |t| t.string "name" t.string "affiliation" t.text "platform" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "nominator_id" end add_index "candidates", ["nominator_id"], name: "index_candidates_on_nominator_id", using: :btree create_table "users", force: :cascade |t| t.string "name" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.string "email", default: "", null: false end add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree add_foreign_key "contributions", "candidates" add_foreign_key "contributions", "users" add_foreign_key "pledges", "candidates" add_foreign_key "pledges", "users" end here factories user , candidate:
factorygirl.define factory :user name faker::name.name email faker::internet.safe_email password faker::internet.password end end factorygirl.define factory :candidate name faker::name.name affiliation faker::team.name platform faker::company.catch_phrase association :nominator, factory: user end end the error keep getting is
rake aborted! nomethoderror: undefined method `name' :candidate:symbol
and has self join , association in candidates factory. error disappears when delete line. glaring errors or suggestions?
the error missing colon before user in factory builder on association line:
factorygirl.define factory :candidate name { faker::name.name } affiliation { faker::team.name } platform { faker::company.catch_phrase } association :nominator, factory: :user end end
Comments
Post a Comment