sjke / pg_ltree Goto Github PK
View Code? Open in Web Editor NEWAdds PostgreSQL's ltree support for ActiveRecord models
License: MIT License
Adds PostgreSQL's ltree support for ActiveRecord models
License: MIT License
This is only in Rails 5.1 and a result of this: https://github.com/sjke/pg_ltree/blob/master/lib/pg_ltree/versions/rails_5_1.rb#L27
Having a hard time wrapping my mind around the need for this i.e. updating the tree path to null to cascade deletes down the tree path. Is the correct workaround (keeping the non-null constraint) to manually cascade deletes by walking down the tree in a depth-first-search deleting all nodes along the way?
https://github.com/sjke/pg_ltree/wiki/List-of-methods-for-work-with-LTree
Class Methods:
#roots Root nodes
#at_depth(depth) Nodes on the depth
#leaves Leaves nodes
#where_path_liked Nodes when path liked the lquery
I've been working on a project that uses this gem, and I'm frequently finding myself wanting to query with joins to root
using ActiveRecord's joins
with root
... however, since root isn't a proper ActiveRecord relationship, that's not possible.
Also, having a family
relationship as well, to bring up all the nodes belonging to the tree :)
@sjke Is this something you'd be interested in? I can gladly take a good try at this, I've already got a plan ๐ and might get some code ready as well.
I used this way:
def as_html_tree
if children.empty?
%Q{<li><a href="/path/#{slug}">#{name}</a></li>}
else
%Q{
<li><a href="/path/#{slug}">#{name}</a>
<ul>
#{children.to_a.map(&:as_html_tree).join("</a>")}
</ul>
</li>
}
end
end
It is right?
Currently a call to model.destroy will remove the model AND remove all other models on the same depth of tree (instead of it's children)
Space Destroy (1.4ms) DELETE FROM "spaces" WHERE "spaces"."id" = $1 [["id", 141]]
Space Destroy (0.7ms) DELETE FROM "spaces" WHERE (spaces.path <@ '133.134.137')
Should be:
Space Destroy (0.7ms) DELETE FROM "spaces" WHERE (spaces.path <@ '133.134.137.141')
Now that Rails 6.0 is released, would it be possible to loosen the Active Record dependency to allow using this gem in Rails 6 projects?
Hi, is it possible to allow support for Rails 7 official releases (seems only compatible with <= 7.0.0.rc1)?
In PR #8, descendents is renamed to descendants. The wiki should be updated to reflect this change.
Hello, normally I wouldn't submit an issue like this with so little information, but I saw this gem had a quite a bit of recent restructuring and a recently redacted 1.2.0 tag.
We've been using this gem and in abnormal load orders we're seeing
NoMethodError: undefined method 'ltree' for Foo:Class
when an ltree attribute would normally be defined. Referencing PgLtree
in that same location results in an uninitialized constant error.
The error will does not occur if that code is preceeded with
require "pg_ltree/ltree"
ActiveSupport.on_load(:active_record) { extend PgLtree::Ltree }
We haven't been able to reproduce it on rails console
or rails server
, but have seen it running rake
tasks and rspec
specs.
An isolated reproduction (i.e. not a branch on our application) has been harder that expected. We're continuing to look into it and will provide more information when we can.
ruby 3.1.2p20
rails 7.0.3
ltree 1.1.9
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.