Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make alias to attributes #39

Closed
lest opened this issue Nov 2, 2011 · 4 comments
Closed

Make alias to attributes #39

lest opened this issue Nov 2, 2011 · 4 comments

Comments

@lest
Copy link
Contributor

lest commented Nov 2, 2011

I am interested in making alias to set of attributes, e.g. instead of writing:

first_name_or_last_name_cont

it would be great to have ability to write simply:

full_name_cont

when somewhere we defines that full_name consists of first_name and last_name

@lest lest closed this as completed Jun 14, 2012
@xinlangzi
Copy link

@ernie

Dear Author, can you give some feedback for the above question? We all need it. thank you.

@momer
Copy link

momer commented Jul 10, 2013

Check out the full_name ransacker from the demo app

@xinlangzi
Copy link

@momer

Thank you for you help! I have a deeper question.

class Article < ActiveRecord::Base
  #has attributes: title, :description
  has_many :comments
end

class Comment < ActiveRecord::Base
   #has attributes :title, :description
   belongs_to :article
end

Now I hope to simply,

keyword_cont

I want to find the keyword inside the article's title and description as well as related comment's title and description.
I have tried the following code to support searching article's title and description,

  ransacker :keyword, formatter: proc{|v| v}, splat_param: true do |parent|
    Arel::Nodes::InfixOperation.new('||', parent.table[:title], parent.table[:description])
  end

Now my questions is how to deal with OUTER JOIN with comments and search title and description on comments in ransacker definition?

@momer
Copy link

momer commented Jul 10, 2013

Drawing right from the example I linked to earlier, check out this SO post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants