현재 첫 번째 프로젝트를 진행 중이며 내 앱에 "friending"을 추가하려고합니다. 그러나 내 데이터베이스에 존재하지 않는 속성이 작동하는 것처럼 보이기 때문에 우정 모델의 개념을 파악하는 데 약간의 어려움이 있습니다.레일 : 우정 조인 테이블 설명
아래 나열된 모델과 데이터베이스 열이 있습니다. 이 테이블은 조인 테이블이지만 사용자 모델에서는 friendships
테이블에없는 경우 friends
, requested_friends
및 pending friends
이 표시됩니다. 가상 조인 테이블이기 때문에 내가 마이그레이션 할 필요없이 필요한 모든 열을 추가 할 수 있습니까?
또한 내 users
테이블에 해당 열이 없더라도 자습서는 결국 @user.pending_friends.each
이됩니다. 나는이 부분에서 꽤 혼란 스럽다.
현재 나는이 간단한 튜토리얼을 통해 갈거야 :
사용자 모델
class User < ActiveRecord::Base
...
...
has_many :friendships, :dependent => :destroy
has_many :friends, :through => :friendships, :conditions => "status = 'accepted'"
has_many :requested_friends, :through => :friendships, :source => :friend, :conditions => "status = 'requested'", :order => :created_at
has_many :pending_friends, :through => :friendships, :source => :friend, :conditions => "status = 'pending", :order => :created_at
끝
우정 모델
class Friendship < ActiveRecord::Base
attr_accessible :friend_id
belongs_to :user
belongs_to :friend, :class_name => "User"
end
: 여기
http://railsforum.com/viewtopic.php?id=16760 내 파일입니다
당신은 아마 당신이 당신의 스키마 status
열이 없기 때문에 마이그레이션 잊어
create_table "friendships", :force => true do |t|
t.integer "user_id"
t.integer "friend_id"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "users", :force => true do |t|
t.string "name"
t.string "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "password_digest"
t.string "remember_token"
end
이것에 대한 결과는 무엇입니까? –