2013-08-25 5 views
1

레일 4 앱에서 작업하고 있으며 개발자 및 앱의 두 모델이 있습니다. 개발자는 많은 앱을 보유 할 수 있으며 많은 앱에 속합니다. (여러 앱 개발자) 성공적으로 설치 테이블을 만들었고 모든 것이 작동하지만 개발자가 다음과 같이 범위를 넓히고 싶습니다. 창안자가 어디서 볼 수있는 앱이나 공동 작업자를 수정할 수 있는지 앱. 최선의 제안은이 기능을 달성하는 것이 었습니다.레일 모델 설정 역할

def change 
    create_table :access_restricts do |t| 
     t.integer :user_id 
     t.integer :application_id 
     t.integer :role_id 

     t.timestamps 
    end 
    end 

사용자 및 응용 프로그램이 많은 assess_restricts이있을 것이다 :

has_and_belongs_to_many :collaborators, class_name: 'Developer', association_foreign_key: :collaborator_id 
    has_and_belongs_to_many :founders, class_name: 'Developer', association_foreign_key: :founder_id 

개발자

has_and_belongs_to_many :apps, foreign_key: 'collaborator_id' 
    has_and_belongs_to_many :apps, foreign_key: 'founder_id' 
+0

어떻게'has_many의 through' 또는'has_and_belongs_to_many'를 통해'App'와'Developer'에 관계를 정의 했습니까? – j03w

+0

@ j03w 질문이 업데이트되었습니다 – ny95

+0

두 가지 선택이 있습니다 1. @zolter 답변에서 제안한 것과 비슷한 테이블을 새로 만들고'hbtm '대신'has_many through'를 사용하십시오.'edit'와'update' 메소드에 약간의 체크가 있습니다 귀하의 컨트롤러에. 2.'hbtm'을 수정하여 적절한 모델 테이블로 만드십시오. 마이그레이션을 추가하여 타임 스탬프 컬럼을 만드십시오. http://stackoverflow.com/questions/7542976/add-timestamps-to-an-existing-table 그리고'role' 컬럼을 추가하십시오 테이블에도. 그런 다음'models' 파일에'model' 파일을 만듭니다. – j03w

답변

1

난 당신이 다른 테이블을 만들 필요가 있다고 생각합니다.