SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with associatotions

    I have these models:

    class Vote < ActiveRecord::Base
    belongs_to :core
    belongs_to :user_id
    end

    class User < Core
    has_many :votes
    end


    class Core < ActiveRecord::Base
    has_many :votes
    end

    the tables in db are:

    cores(id,name)

    votes(id,core_id,user_id,vote)


    when i do some query to votes, the attribute core_id is confused with
    user_id.
    (core_id is the user or others objects that are voted, user_id is the
    voter)

    How i can do to distinct the voter and the user voted?
    Thanks

  2. #2
    l 0 l silver trophybronze trophy lo0ol's Avatar
    Join Date
    Aug 2002
    Location
    Palo Alto
    Posts
    5,329
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I think your problem is in the belongs_to :user_id. Unless you have a funky naming pattern in your models going on, you'll probably want to do belongs_to :user.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •