Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8625869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:52:57+00:00 2026-06-12T07:52:57+00:00

I’m still having trouble searching for technologies that are stored in a separate table,

  • 0

I’m still having trouble searching for technologies that are stored in a separate table, where there is a relationship between the technology table (technol) and Project table through a table called projecttechnol.

This is my log when I try to search for a project with a technology (tech1).

Parameters: {"utf8"=>"✓", "client"=>"", "industry"=>"", "role"=>"", "technols"=>{"id"=>["", "1", ""]}, "business_div"=>"", "project_owner"=>"",  "start_date_dd"=>"", "start_date_A"=>"", "start_date_B"=>"", "status"=>"", "keywords"=>"", "per_page"=>"10"}
  User Load (0.6ms)  SELECT "users".* FROM "users" WHERE "users"."id" = 1 LIMIT 1
  Technol Load (0.3ms)  SELECT "technols".* FROM "technols" 
  Project Load (0.5ms)  SELECT "projects".* FROM "projects" ORDER BY client
  Project Load (0.6ms)  SELECT "projects".* FROM "projects" ORDER BY industry
  Project Load (0.4ms)  SELECT "projects".* FROM "projects" ORDER BY role
  Project Load (0.4ms)  SELECT "projects".* FROM "projects" ORDER BY tech
  CACHE (0.0ms)  SELECT "projects".* FROM "projects" ORDER BY tech
  CACHE (0.0ms)  SELECT "projects".* FROM "projects" ORDER BY tech
  CACHE (0.0ms)  SELECT "projects".* FROM "projects" ORDER BY tech
  CACHE (0.0ms)  SELECT "projects".* FROM "projects" ORDER BY tech
  CACHE (0.0ms)  SELECT "projects".* FROM "projects" ORDER BY tech
  Project Load (0.6ms)  SELECT "projects".* FROM "projects" ORDER BY business_div
  Project Load (0.5ms)  SELECT "projects".* FROM "projects" ORDER BY project_owner
  Project Load (0.7ms)  SELECT "projects".* FROM "projects" ORDER BY status
   (0.9ms)  SELECT COUNT(*) FROM "projects" INNER JOIN "projecttechnols" ON "projecttechnols"."project_id" = "projects"."id" INNER JOIN "technols" ON "technols"."id" = "projecttechnols"."technol_id" WHERE "technols"."id" IS NULL

Here is my project.rb:

class Project < ActiveRecord::Base
      attr_accessible :edited_first_name, :edited_last_name, :first_name, :last_name, :business_div, :client, :customer_benifits, :edited_date, :end_date, :entry_date,  :financials, :industry, :keywords, :lessons_learned, :project_name, :project_owner, :role, :start_date, :status, :summary, :tech_id

    validates_presence_of :business_div, :client, :customer_benifits, :end_date,  :financials, :industry, :keywords, :lessons_learned, :project_name, :project_owner, :role, :start_date, :status, :summary#, :tech



    has_many :projecttechnols
    has_many :technols, :through => :projecttechnols


    def self.like(text); "%#{text}%"; end

      def self.search(search_client, search_industry, search_role, search_tech_id, search_business_div, search_project_owner, search_status, search_start_date_dd, search_start_date_A, search_start_date_B,  search_keywords)
        # start with a scoped query, to apply more scopes on it afterwards
        _projects = Project.scoped 
        # then, for each of the parameters, apply the scope only if present
        if search_client.present?
          _projects = _projects.where ['client LIKE ?', like(search_client)] 
        end
        if search_industry.present?
          _projects = _projects.where ['industry LIKE ?', like(search_industry)]
        end
        if search_role.present?
          _projects = _projects.where ['role LIKE ?', like(search_role)]
        end


       _projects = _projects.joins(:technols).
              where("technols.id" => search_techs_ids)

        if search_business_div.present?
          _projects = _projects.where ['business_div LIKE ?', like(search_business_div)]
        end
        if search_project_owner.present?
          _projects = _projects.where ['project_owner LIKE ?', like(search_project_owner)]
        end

         if search_status.present?
          _projects = _projects.where ['status LIKE ?', like(search_status)]
        end



    todays_date = DateTime.now.to_date

    if !search_start_date_A.blank? or !search_start_date_B.blank?
        search_start_date_A = Date.parse(search_start_date_A).strftime("%Y-%m-%d")
        search_start_date_B = Date.parse(search_start_date_B).strftime("%Y-%m-%d")
        todays_date = nil
        search_start_date_dd = nil

        end

    if search_start_date_dd.blank?
        todays_date = nil
    end


    if search_start_date_A.present? or search_start_date_B.present?

          _projects = _projects.where [' DATE(start_date) BETWEEN ? AND ?', search_start_date_A, search_start_date_B]
        end


                    if search_start_date_dd.present?
          _projects = _projects.where ['DATE(start_date) BETWEEN ? AND ?', search_start_date_dd, todays_date]
        end




        if search_keywords.present?
          _projects = _projects.where ['keywords LIKE ?', like(search_keywords)]
        end
        # now you have applied only the present scopes. return the result, and watch 
        # the query as it executes.
        _projects
      end


    def self.paginated_for_index(projects_per_page, current_page)
        paginate(:per_page => projects_per_page, :page => current_page)
      end

    end

Technol.rb:

class Technol < ActiveRecord::Base
  attr_accessible :tech

has_many :projecttechnols
has_many :projects, :through => :projecttechnols
end

Projecttechnol.rb

class Projecttechnol < ActiveRecord::Base
  attr_accessible :project_id, :technol_id

belongs_to :technol
belongs_to :project
end

Can anyone see a solution to this work properly. I am new to rails, so please remember this when attempting to help me. Searching for anything in the technology field returns nothing. Thanks a lot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:52:58+00:00Added an answer on June 12, 2026 at 7:52 am

    It looks like you’ve got a typo here in your search parameters:

      def self.search(search_client, search_industry, search_role, search_tech_id...
    

    But yet you use search_techs_id here:

      _projects = _projects.joins(:technols).where("technols.id" => search_techs_ids)
    

    If you examine your queries you can see that its trying to join the two tables with a NULL.

    On another note, your search query is a bit long and tough to read, may I suggest using something like this:

    class Project < ActiveRecord::Base
      attr_accessible :edited_first_name, :edited_last_name, :first_name, :last_name, 
        :business_div, :client, :customer_benifits, :edited_date, :end_date, :entry_date,  
        :financials, :industry, :keywords, :lessons_learned, :project_name, :project_owner, 
        :role, :start_date, :status, :summary, :tech_id
    
      validates_presence_of :business_div, :client, :customer_benifits, :end_date,  
       :financials, :industry, :keywords, :lessons_learned, :project_name, :project_owner, 
       :role, :start_date, :status, :summary#, :tech
    
      has_many :projecttechnols
      has_many :technols, :through => :projecttechnols
    
      scope :client, { |client| where ['client LIKE ?', like(client) ] }
      scope :industry, { |industry| where ['industry LIKE ?', like(industry)] }
      scope :role, { |role| where ['role LIKE ?', like(search_role)] }
      scope :technologies, { |technology_ids| joins(:technols).where("technols.id}" => technology_ids) }
      scope :division, { |division| where ['business_div LIKE ?', like(search_business_div)] }
      scope :owner, { |owner| where ['project_owner LIKE ?', like(search_project_owner)] }
      scope :status, { |status| where ['status LIKE ?', like(search_status)] }
      scope :keywords, { |keywords| where ['keywords LIKE ?', like(keywords)] }
      scope :started_before, { |date| where ['start_date <= ?',date] }
      scope :started_after, { |date| where ['start_date >= ?',date] }
    
      def self.search_fields    
        [:client,:industry,:role,:technologies,:division,:owner,:status,:started_before,:started_after,:keywords]
      end
    
      def self.search(params)
        search_fields.inject(scoped) do |scopes,key|
          params[key].present? ? scopes.send(key,params[key]) : scopes
        end
      end
    
      def self.like(text); "%#{text}%"; end
    
      def self.paginated_for_index(projects_per_page, current_page)
        paginate(:per_page => projects_per_page, :page => current_page)
      end
    
    end
    

    This way, your search method is quite a bit shorter, and since you’ve broken out all these parameters into their own scopes, if you need to reuse them, method is already there.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.