ancestry

在关系数据库中存储分层数据有哪些选择? [关闭]

蓝咒 提交于 2020-08-13 12:23:55
问题: Good Overviews 良好的概述 Generally speaking, you're making a decision between fast read times (for example, nested set) or fast write times (adjacency list). 一般来说,您要在快速读取时间(例如,嵌套集)或快速写入时间(邻接列表)之间做出决定。 Usually, you end up with a combination of the options below that best fit your needs. 通常,您最终会得到以下最适合您的选项的组合。 The following provides some in-depth reading: 下面提供一些深入的阅读: One more Nested Intervals vs. Adjacency List comparison : the best comparison of Adjacency List, Materialized Path, Nested Set and Nested Interval I've found. 嵌套间隔与邻接列表的另一个比较 :邻接列表,物化路径,嵌套集和嵌套间隔 的最佳比较 。 Models for hierarchical data

How to generate json tree from ancestry

依然范特西╮ 提交于 2020-01-21 06:41:46
问题 I use ancestry to make a tree of goals. I would like to send the contents of that tree to the browser using json. My controller is like this: @goals = Goal.arrange respond_to do |format| format.html # index.html.erb format.xml { render :xml => @goals } format.json { render :json => @goals} end When I open the json file, I get this output: {"#<Goal:0x7f8664332088>":{"#<Goal:0x7f86643313b8>":{"#<Goal:0x7f8664331048>":{"#<Goal:0x7f8664330c10>":{}},"#<Goal:0x7f8664330e68>":{}},"#<Goal

Polymorphic Comments with Ancestry Problems

烈酒焚心 提交于 2020-01-06 01:59:25
问题 I am trying to roll together two Railscasts: http://railscasts.com/episodes/262-trees-with-ancestry and http://railscasts.com/episodes/154-polymorphic-association on my app. My Models: class Location < ActiveRecord::Base has_many :comments, :as => :commentable, :dependent => :destroy end class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end My Controllers: class LocationsController < ApplicationController def show @location = Location.find(params[:id]) @comments

Ember.js model to be organised as a tree structure

末鹿安然 提交于 2019-12-24 00:24:48
问题 I am learning Ember.js, using a Rails backend. I'm looking to set up a tree structure for relating a Group model to itself (Sub-Groups). Since it's pretty mature, I'd like to link up the Ancestry gem for consumption on the Ember side. Ancestry adds a string column called "ancestry" to my Group model, and returns a string of parent ids. How would one approach the setting up Ember models in this case? 回答1: I figured it out with some tinkering around with the group serializer and Ember model. #

Creating has_many association with ancestry gem

倖福魔咒の 提交于 2019-12-23 04:26:56
问题 I installed ancestry gem & create Location Structure. Alaska California Los Angeles Fresno Cincotta (Fresno) Hammond (Fresno) Melvin (Fresno) Melvin 1 Melvin 2 Melvin 3 Arizona Colorado My post and location model class Location < ActiveRecord::Base include Tree has_many :posts end class Post < ActiveRecord::Base belongs_to :location end When i am add new post, how to display only depth 4 level ( Melvin 1,Melvin 2,Melvin 3 ) as drop down. 回答1: You have to enable cache depth so you can use at

Ancestry - how to get all parent without children?

你说的曾经没有我的故事 提交于 2019-12-22 13:53:01
问题 I am doing it this way: @disabled_options = [] Category.where('ancestry is NULL').each do |cat| @disabled_options << cat.id if cat.has_children? end Is there any more elegant way to get all parent without children? 回答1: Category.where("id IN (SELECT parent_id FROM categories)") Assuming parent_id is a field pointing to the parent category. This will select those categories that are pointed to using "parent_id", so if there's a child, the child will have "parent_id" set, therefore the category

Association between Post and Location

隐身守侯 提交于 2019-12-14 03:34:04
问题 This my first ruby on rails application. Model Location and Post, Location has many post.I create location as tree structure with ancestry gem. class Post < ActiveRecord::Base belongs_to :location, :counter_cache => true end class Location < ActiveRecord::Base include Tree has_ancestry :cache_depth => true has_many :posts end This my Post Controller class PostsController < ApplicationController before_action :set_post, only: [:show, :edit, :update, :destroy] def index @posts = Post.all end

How to stop this array of attributes from showing in my view? [duplicate]

假如想象 提交于 2019-12-13 05:52:53
问题 This question already has answers here : What is the difference between <%, <%=, <%# and -%> in ERB in Rails? (7 answers) Closed 4 months ago . I have an annoying problem where my view keeps displaying an array of my object's attributes! My submenu is suppose to show categories in a tree form, which works, but it also shows this annoying array! [ <#Category id: 26, title: "subtest", description: "a test within a test, testception", created_at: "2015-03-01 03:15:29", updated_at: "2015-03-03 01

Rails ancestry: Get children records of ancestry model

流过昼夜 提交于 2019-12-12 03:52:55
问题 I've two models: Post - category_id Category (ancestry model) The category tree looks for example like this: - Root Category - Sub Category Now lets say a post gets categorized to Sub Category. I'm in the Root Category and i would like to see all posts which are in Sub Category as well. Is it possible to get these as well with ancestry? The category tree always has just one nested level so maybe ancestry is anyways too much.. Thanks in advance Working example for just one nested level

Can I create an activerecord association through an activerecord relation (when using the ancestry gem)?

心已入冬 提交于 2019-12-10 17:17:14
问题 I am using the ancestry gem in my rails project to create a hierarchy of groups. A group can belong to a parent group and can have many children groups. Each group can have many users who belong to a group. The model looks like this: class Group < ActiveRecord::Base has_ancestry has_many :users end I would love to be able to get all users for the descendants of a group, something like this: class Group < ActiveRecord::Base has_ancestry has_many :users has_many :descendants_users, through: