Module: Paraphrase::Syntax::Relation

Defined in:
lib/paraphrase/syntax.rb

Instance Method Summary collapse

Instance Method Details

#paraphrase(params) ⇒ Paraphrase::Query

Creates a paraphrase query, supplying self as the base for the query. Intended for scoping a query from an association:

Given the following models:

class User < ActiveRecord::Base
  has_many :posts
end

class Post < ActiveRecord::Base
  belongs_to :user

  register_mapping
    map :title_like, :to => :title
  end
end

It is possible to do the following:

user.posts.paraphrase({ :title => 'Game of Thrones Finale' }).to_sql
# => SELECT `posts`.* FROM `posts` INNER JOIN `users` ON `users`.`post_id` = `posts`.`id` WHERE `posts`.`title LIKE "%Game of Thrones Finale%";

Parameters:

  • params (Hash)

    query parameters

Returns:



63
64
65
# File 'lib/paraphrase/syntax.rb', line 63

def paraphrase(params)
  klass.paraphraser.new(params, self)
end