Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Watched through "Rails 3 Essential Training" chapter on associations and read through Rails guides write up on Active Record associations. Before I was searching the name, the tags, the skill individually and collecting the ID's in succession. With the proper polymorphic association you can search all the parameters in a single search method.</p> <p>Person Model.</p> <pre><code>has_one :sharing_skill, :as =&gt; :marker, :conditions =&gt; ['marker_type = ?', 'Person'] has_one :skill, :through =&gt; :sharing_skill define_index do indexes name indexes tag_taggings.tag(:name), :as =&gt; :tags indexes skill(:name), :as =&gt; :skill has :id has created_at end </code></pre> <p>Group Model.</p> <pre><code>has_one :sharing_skill, :as =&gt; :marker, :conditions =&gt; ['marker_type = ?', 'Group'] has_one :skill, :through =&gt; :sharing_skill define_index do indexes name indexes tag_taggings.tag(:name), :as =&gt; :tags indexes skill(:name), :as =&gt; :skill has :id has created_at end </code></pre> <p>Sharing_skill.model</p> <pre><code>belongs_to :marker, :polymorphic =&gt; true belongs_to :skill </code></pre> <p>Skill model.</p> <pre><code>has_one :sharing_skill has_one :person, :through =&gt; :sharing_skill, :source =&gt; :marker has_one :group, :through =&gt; :sharing_skill, :source =&gt; :marker </code></pre> <p>Search Controller.</p> <pre><code>#SEARCH NAME, TAGS, AND SKILL conditions = {} %w(name tags skill).each do |i| i = i.to_sym next unless params[i] conditions[i] = params[i] end person = Person.search(params[:search], :conditions =&gt; conditions, :per_page =&gt; 999999) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload