Class ThinkingSphinx::Association
In: lib/thinking_sphinx/association.rb
Parent: Object

Association tracks a specific reflection and join to reference data that isn‘t in the base model. Very much an internal class for Thinking Sphinx - perhaps because I feel it‘s not as strong (or simple) as most of the rest.

Methods

Attributes

join  [RW] 
parent  [RW] 
reflection  [RW] 

Public Class methods

Get the children associations for a given class, association name and parent association. Much like the instance method of the same name, it will return an empty array if no associations have the name, and only have multiple association instances if the underlying relationship is polymorphic.

  Association.children(User, :pages, user_association)

Create a new association by passing in the parent association, and the corresponding reflection instance. If there is no parent, pass in nil.

  top   = Association.new nil, top_reflection
  child = Association.new top, child_reflection

Public Instance methods

Returns an array of all the associations that lead to this one - starting with the top level all the way to the current association object.

Get the children associations for a given association name. The only time that there‘ll actually be more than one association is when the relationship is polymorphic. To keep things simple though, it will always be an Array that gets returned (an empty one if no matches).

  # where pages is an association on the class tied to the reflection.
  association.children(:pages)

Returns true if the association - or a parent - is a has_many or has_and_belongs_to_many.

Link up the join for this model from a base join - and set parent associations’ joins recursively.

Returns the association‘s join SQL statements - and it replaces

::ts_join_alias:with the aliased table name so the generated reflection

join conditions avoid column name collisions.

[Validate]