결과 보여는 조건으로 포함하지만, 항상 기본 테이블이처럼이 기능이
# get all locations, if the user has discovered them or not
def self.getAll(user)
self.find(:all, :order => 'min_level asc', :include => 'discovered_locations',
:conditions => [ "discovered_locations.user_id = ? OR discovered_locations.id is null", user.id])
end
자기가 실제로 BossLocation 모델입니다. 나는 bosslocation의 결과 집합과 그 위치가 내 사용자에 의해 발견 된 경우 발견 된 위치를 원합니다. 그러나 그것이 발견되지 않았다면, 나는 아직도 bosslocation과 발견 된 위치로서의 어떤 물체도 필요로하지 않습니다. 위의 코드를 사용하여 사용자가 아무 것도 발견하지 못했다면 나는 bosslocations를 전혀 얻지 못합니다.
편집 :
이내 연관이있는 것처럼 :
이class BossLocation < ActiveRecord::Base
has_many :discovered_locations
has_many :users, :through => :discovered_locations
class DiscoveredLocation < ActiveRecord::Base
belongs_to :user
belongs_to :boss_location
class User < ActiveRecord::Base
has_many :discovered_locations
has_many :boss_locations, :through => :discovered_locations
음, 사실은 이미 연관성이 있습니다. 코드는 매우 논리적이지만 문제는 결과를 파싱하는 것입니다. 알다시피, 나는이 보스 위치가 사용자를 위해 잠겨 있지 않은 것처럼 정적 bosslocation 정보를 가질 필요가 있습니다. 아마도 @ location.each를 수행하고 각 위치에 대한 정적 정보를 출력하고 어떤 정보가 사용자에 대해 잠겨 있는지 지정할 수 있습니다. 나는 그것이 @bl과 @dbl을 따로 갖는 것에 지루할 것이라고 생각한다. – Spyros
원래 코드에서 내 질문에 연관성이 있으므로 연결을 붙여 넣습니다. – Spyros
@location을 할 때.각각의 위치에서 각각의 위치가 discover_locations에 있는지 쉽게 확인할 수 있습니다. 모두 내 게시물을 업데이트합니다. – DanneManne