Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Nathan Flood
    The repository readme says that the gem is compatible with Rails 3, any known issues working with Rails 4?
    Nope, it should work fine.
    Nathan Flood
    Thanks arjan, so far everything is going fine.

    Hi. Ancestry provides scopes like "ancestors_of, subtree_of", etc. But these scopes are Class ones, and can not be chained to other scopes.
    For instance, if i have "scope :open, :conditions => 'open = 1'", i cannot chain it with Ancestry scopes like : "Model.open.subtree".

    Is there a way to perform such operation?

    Does it work the other way around?
    No. The scope "subtree" only exists as an instance method, so that i can only get the subtree of one node.
    True, so what is it that you are trying to achieve with your original question?
    You want all the models that are "open"
    but what should adding subtree do?

    I have a scope like this : named_scope :open, :conditions => "brand is not null", and i would like to select all models that are subtree of this scope.
    Currently, i have to build a loop and selecting all subtrees of each model ; that is not efficient at all (n requests rather than 1).

    I found an other solution, that is not perfect since its not really chainable, and looks like this :

    named_scope :branded, lambda {{
    :joins => "LEFT JOIN groups AS ancestors ON (
    groups.ancestry = ancestors.id
    OR groups.ancestry LIKE CONCAT(ancestors.id,'/%')
    OR groups.ancestry LIKE CONCAT('%/', CONCAT(ancestors.id,'/%'))
    OR groups.ancestry LIKE CONCAT('%/',ancestors.id)
    OR ancestors.id = groups.id
    :conditions => '(ancestors.brand IS NOT NULL AND ancestors.brand !="")'

    I wished Ancestry provided real scopes that are chainables and did this job.
    Matt Hink
    So, quick question. How well does Ancestry play with the 'ltree' column type in Postgres?
    @mhink Late answer. AFAIK it doesn't. Ancestry utilizes a string column and stores paths like ":parent_id/:grand_parent_id". It constructs where queries in Arel that match forementioned string. In theory you could add very basic support for LTREE by using ltree2text when LTREE is used instead of a string column, but that would only slow performance. Adding full support for LTREE could be done as well, but would require some more work. Feel free to create a pull-request if you are up for it.
    Jimmy Baker
    Does anyone know how to property set a parent when using fixtures in rails 4?
    Matthew Brown
    Ancestry has been extremely useful since rails 1.2.6 for me. Is it still alive? I see we have glitter here, so that's a good sign....
    Matthew Brown
    Rishav Paul
    Hi, how can I order siblings in ancestry?
    Brandon Lawrence
    whats the syntax for adding an ancester to an object on creation?
    I tried Product.create(:name => 'Cheap Koozies', :parent => 'Drinkware') but it didn't work. The Drinkware object already exists

    @jimmybaker In rails 2, i do this :
    name: Grand parent

    name: Parent
    ancestry: '<%= Fixtures.identify(:grand_parent) %>'

    ancestry: '<%= Fixtures.identify(:grand_parent) %>/<%= Fixtures.identify(:parent) %>'

    Kyle Tully
    Hi All,
    Am using Ancestry inside a mountable engine on rails 4.2.2 and receive the following error "undefined local variable or method `has_ancestry' when adding "has_ancestry" to the model.rb file
    Is there anything different needed when installing Ancestry within a mountable engine?
    Oleksandr Bratashov

    Hello guys, could you help me with some question, when i setup ancestry for my model Category and create 4 items wich includes each other, last item has depth 2, but it shuld be 4 http://prntscr.com/br8hww

    A - 1
    B - 2
    C - 2 (should be 3)
    D - 2 (should be 4)

    Denny Mueller
    Hey anyone available for a second?
    Jason Frey
    what's up @dennym ?