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

Ancestry and pg_search and order scope #220

Open
phlegx opened this issue Jan 19, 2015 · 3 comments
Open

Ancestry and pg_search and order scope #220

phlegx opened this issue Jan 19, 2015 · 3 comments

Comments

@phlegx
Copy link

phlegx commented Jan 19, 2015

Hi!

Any idea how to use ancestry and pg_search (https://github.com/Casecommons/pg_search)? I want to search on all parents.

# app/models/zone.rb

class Zone < ActiveRecord::Base
  include PgSearch
  pg_search_scope :search,
      against: :name, associated_against: {
          parent: :name,
      }
...

Search using Zone.all.search('My By Parent Name')

Another question: is it possible to order all zones by its parents name?

# app/models/zone.rb

class Zone < ActiveRecord::Base
...
    scope :order, -> { order('parents.name ASC') }
...
@vanderhoorn
Copy link
Contributor

I'm not sure how pg_search works and/or combines with ancestry. But do note that ancestry's parent_id is not an Active Record column, but a method. Ancestry only uses (by default) the ancestry column.

@phlegx
Copy link
Author

phlegx commented Jan 19, 2015

@vanderhoorn ok thank you. But how can I order all Zones by its parent name?

@kbrock
Copy link
Collaborator

kbrock commented Nov 1, 2018

I would like to introduce parent_id as a scope or actual sql. Will look into this but to be honest, probably won't happen any time soon

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