scopes.rb revision 7f12123144c64e1114c5fc62158230fa96706746
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen scope :without_parent, where('ontologies.parent_id' => nil)
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen joins(:ontology_version).where('ontology_versions.basepath' => path)
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen order('ontologies.state asc, ontologies.symbols_count desc')
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen condition = <<-CONDITION
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen ("ontology_versions"."file_extension" = :extname)
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen OR (("ontology_versions"."file_extension" IS NULL)
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen AND ("ontologies"."file_extension" = :extname))
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen with_basepath(File.basepath(path)).
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen where(condition, extname: File.extname(path)).
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen readonly(false)
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen scope :with_basepath, ->(path) do
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen join = <<-JOIN
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen LEFT JOIN "ontology_versions"
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen ON "ontologies"."ontology_version_id" = "ontology_versions"."id"
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen condition = <<-CONDITION
96ca70b91de9f2b07728812bbec222e18f121cbdTimo Sirainen ("ontology_versions"."basepath" = :path)
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen OR (("ontology_versions"."basepath" IS NULL)
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen AND ("ontologies"."basepath" = :path))
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen joins(join).where(condition, path: path).readonly(false)
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen scope :parents_first, -> do
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen order('(CASE WHEN ontologies.parent_id IS NULL THEN 1 ELSE 0 END) DESC,'\
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen ' ontologies.parent_id asc')
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen # searching scopes
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen scope :filter_by_ontology_type, ->(type_id) do
baf3e87e186453fda13bd21f7cbcb2efc8492e8bTimo Sirainen where(ontology_type_id: type_id)
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen scope :filter_by_project, ->(project_id) do
0cc566d5e68a650d12fd73631d53a467fad72e1eTimo Sirainen joins(:projects).where("projects.id = #{project_id}")