मेरे पास Page
मॉडल है जिसमें Section
मॉडल हैं जो SectionRevision
से current_revision
के माध्यम से जुड़े हुए हैं। Page
मॉडल से मैं सभी Sections
चुनने का प्रयास कर रहा हूं जहां current_revision.parent_section_id
शून्य नहीं है।रेल। कहीं() विशेषता शून्य नहीं है
Section
मॉडल:
class Section < ActiveRecord::Base
belongs_to :page
has_many :revisions, :class_name => 'SectionRevision', :foreign_key => 'section_id'
has_many :references
has_many :revisions, :class_name => 'SectionRevision',
:foreign_key => 'section_id'
belongs_to :current_revision, :class_name => 'SectionRevision', :foreign_key => 'current_revision_id'
delegate :position, to: :current_revision
def set_current_revision
self.current_revision = self.revisions.order('created_at DESC').first
end
def children
Section.includes(:current_revision).where(:section_revisions => {:parent_section_id => self.id})
end
end
और Page
मॉडल:
class Page < ActiveRecord::Base
belongs_to :parent, :class_name => 'Page', :foreign_key => 'parent_page_id'
has_many :children, :class_name => 'Page', :foreign_key => 'parent_page_id'
belongs_to :page_image, :class_name => 'Image', :foreign_key => 'page_image_id'
has_many :sections
validates_uniqueness_of :title, :case_sensitive => false
def top_level_sections
self.sections.includes(:current_revision).where(:section_revisions => {:parent_section_id => "IS NOT NULL"})
end
end
Page.top_level_sections
के आधार पर लिखा है: Rails where condition using NOT NULL और वर्तमान में एक खाली सरणी पैदा करता है। यह सही ढंग से पता नहीं लगाता है कि "parent_section_id" शून्य नहीं है।
मैं Page.top_level_sections
सही तरीके से कैसे लिखूं?
'Page.top_level_sections' की मंशा क्या है? क्या यह उन अनुभागों को खोजने का प्रयास कर रहा है जिनमें कोई संशोधन नहीं है? – CubaLibre
उन अनुभागों को खोजने का प्रयास कर रहा है जहां current_revision.parent_section_id शून्य नहीं है। –