From peter.schrammel at gmx.de Fri Apr 4 13:31:02 2008 From: peter.schrammel at gmx.de (Peter Schrammel) Date: Fri, 04 Apr 2008 19:31:02 +0200 Subject: [Betternestedset-talk] root with scope? Message-ID: <47F665D6.1000400@gmx.de> Hi, I'm trying to get the root of a scoped set but all I get is: r=Album.root(:user_id=>4) ArgumentError: Unknown key(s): user_id My code is quite simple: class Album < ActiveRecord::Base acts_as_nested_set :scope => :user end The db has a user_id column and the columns BNS needs (parent_id,lft,rgt). I'm useing the svn trunk of today. Any tips (I hope the bug is between my ears)? Thanks, Peter From beholdthepanda at gmail.com Fri Apr 4 15:16:43 2008 From: beholdthepanda at gmail.com (Stephen Schor) Date: Fri, 4 Apr 2008 15:16:43 -0400 Subject: [Betternestedset-talk] root with scope? In-Reply-To: <47F665D6.1000400@gmx.de> References: <47F665D6.1000400@gmx.de> Message-ID: <45e5e9bc0804041216x52486730pe7d5eb1ab0e4a6b5@mail.gmail.com> Hi Peter, My table contains multiple roots using scope. I've never really called .root on the class. I've sometimes wanted to find the root of an instance by calling my_instance.root to return the top-most ancestor or my_instance. Also - looking at the comments of .root in the SingletonMethods module - there's this info... # Returns the single root for the class (or just the first root, if there are several). # Deprecation note: the original acts_as_nested_set allowed roots to have parent_id = 0, # so we currently do the same. This silliness will not be tolerated in future versions, however. I hope this is helpful to you. -Stephen On Fri, Apr 4, 2008 at 1:31 PM, Peter Schrammel wrote: > Hi, > > I'm trying to get the root of a scoped set but all I get is: > > r=Album.root(:user_id=>4) > ArgumentError: Unknown key(s): user_id > > My code is quite simple: > > class Album < ActiveRecord::Base > acts_as_nested_set :scope => :user > end > > The db has a user_id column and the columns BNS needs (parent_id,lft,rgt). > > I'm useing the svn trunk of today. Any tips (I hope the bug is between > my ears)? > > > Thanks, > > Peter > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080404/4825d281/attachment.html From peter.schrammel at gmx.de Fri Apr 4 15:31:08 2008 From: peter.schrammel at gmx.de (Peter Schrammel) Date: Fri, 04 Apr 2008 21:31:08 +0200 Subject: [Betternestedset-talk] root with scope? In-Reply-To: <45e5e9bc0804041216x52486730pe7d5eb1ab0e4a6b5@mail.gmail.com> References: <47F665D6.1000400@gmx.de> <45e5e9bc0804041216x52486730pe7d5eb1ab0e4a6b5@mail.gmail.com> Message-ID: <47F681FC.4090000@gmx.de> Thanks Stephen but if you look at the code further down: def root(scope = {}) find_in_nested_set(:first, { :conditions => "(#{prefixed_parent_col_name} IS NULL OR #{prefixed_parent_col_name} = 0)" }, scope) end So the so called inner_scope is set to the scope I pass. But then somewhere in find_in_nested_set it throws the error...sigh. Nobody ever needed the root of a scope (I have only one per scope)? Stephen Schor schrieb: > Hi Peter, > > My table contains multiple roots using scope. I've never really called > .root on the class. > I've sometimes wanted to find the root of an instance by calling > my_instance.root to return > the top-most ancestor or my_instance. > > Also - looking at the comments of .root in the SingletonMethods module - > there's this info... > > # Returns the single root for the class (or just the first root, if > there are several). > # Deprecation note: the original acts_as_nested_set allowed roots to > have parent_id = 0, > # so we currently do the same. This silliness will not be tolerated in > future versions, however. > > I hope this is helpful to you. > From tiwatson at gmail.com Fri Apr 4 15:46:12 2008 From: tiwatson at gmail.com (Tim Watson) Date: Fri, 4 Apr 2008 15:46:12 -0400 Subject: [Betternestedset-talk] root with scope? In-Reply-To: <47F681FC.4090000@gmx.de> References: <47F665D6.1000400@gmx.de> <45e5e9bc0804041216x52486730pe7d5eb1ab0e4a6b5@mail.gmail.com> <47F681FC.4090000@gmx.de> Message-ID: <959562ce0804041246o24af0895vda2bcbcfc37c1d4f@mail.gmail.com> Would you not use.. user.albums.root() ? On Fri, Apr 4, 2008 at 3:31 PM, Peter Schrammel wrote: > Thanks Stephen > > but if you look at the code further down: > def root(scope = {}) > find_in_nested_set(:first, { :conditions => > "(#{prefixed_parent_col_name} IS NULL OR #{prefixed_parent_col_name} = > 0)" }, scope) > end > > So the so called inner_scope is set to the scope I pass. But then > somewhere in find_in_nested_set it throws the error...sigh. > > Nobody ever needed the root of a scope (I have only one per scope)? > > > Stephen Schor schrieb: > > Hi Peter, > > > > My table contains multiple roots using scope. I've never really called > > .root on the class. > > I've sometimes wanted to find the root of an instance by calling > > my_instance.root to return > > the top-most ancestor or my_instance. > > > > Also - looking at the comments of .root in the SingletonMethods module - > > there's this info... > > > > # Returns the single root for the class (or just the first root, if > > there are several). > > # Deprecation note: the original acts_as_nested_set allowed roots to > > have parent_id = 0, > > # so we currently do the same. This silliness will not be tolerated in > > future versions, however. > > > > I hope this is helpful to you. > > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080404/e427592c/attachment.html From cnk at caltech.edu Mon Apr 7 21:18:52 2008 From: cnk at caltech.edu (Cynthia Kiser) Date: Mon, 7 Apr 2008 18:18:52 -0700 Subject: [Betternestedset-talk] root with scope? In-Reply-To: <47F665D6.1000400@gmx.de> References: <47F665D6.1000400@gmx.de> Message-ID: <20080408011852.GN15268@inky.caltech.edu> Quoting Peter Schrammel : > I'm trying to get the root of a scoped set but all I get is: > > r=Album.root(:user_id=>4) > ArgumentError: Unknown key(s): user_id > > My code is quite simple: > > class Album < ActiveRecord::Base > acts_as_nested_set :scope => :user > end > > The db has a user_id column and the columns BNS needs (parent_id,lft,rgt). I think you need to specify 2 things - what the user id is, and that you want the root of that set. In the model where I similarly want the root of someones things, I do the following: def self.find_persons_base_page(person_id) return PersonalPage.find_by_person_id_and_parent_id(person_id, nil) end -- Cynthia Kiser From peter.schrammel at gmx.de Tue Apr 8 03:10:05 2008 From: peter.schrammel at gmx.de (Peter Schrammel) Date: Tue, 08 Apr 2008 09:10:05 +0200 Subject: [Betternestedset-talk] root with scope? In-Reply-To: <20080408011852.GN15268@inky.caltech.edu> References: <47F665D6.1000400@gmx.de> <20080408011852.GN15268@inky.caltech.edu> Message-ID: <47FB1A4D.2010109@gmx.de> Thank you all, I already wrote my own #root(user) method (same solution as Cynthia) but I think the docs/lib have a bug here. It says #root(scope={}) will return the (first) root of my set(s). That is right if you don't use scope but throws an error if you do. My issue was pointing out this bug (although I hoped it was just a mistake by me). Regards Peter I know I should write a test for this....test.write if me.sparetime.have? Cynthia Kiser schrieb: > Quoting Peter Schrammel : >> I'm trying to get the root of a scoped set but all I get is: >> >> r=Album.root(:user_id=>4) >> ArgumentError: Unknown key(s): user_id >> >> My code is quite simple: >> >> class Album < ActiveRecord::Base >> acts_as_nested_set :scope => :user >> end >> >> The db has a user_id column and the columns BNS needs (parent_id,lft,rgt). > > I think you need to specify 2 things - what the user id is, and that > you want the root of that set. In the model where I similarly want the > root of someones things, I do the following: > > def self.find_persons_base_page(person_id) > return PersonalPage.find_by_person_id_and_parent_id(person_id, nil) > end > > From tom999 at gmx.net Fri Apr 11 16:34:30 2008 From: tom999 at gmx.net (Tom) Date: Fri, 11 Apr 2008 22:34:30 +0200 Subject: [Betternestedset-talk] BetterNestedSet + ":dependent => :destroy" = BUG ? Message-ID: <47FFCB56.9050909@gmx.net> Hi there, I use the plugin "BetterNestedSet" for a model and need to have the model option ":dependent => :destroy" at the same time. Using only one of these two things works perfectly. But using both at the same time keeps throwing an error. I have the following model structure (which is part of a slightly bigger structure): class Group < ActiveRecord::Base has_many :groupmessages, :dependent => :destroy end class Groupmessage < ActiveRecord::Base belongs_to :group acts_as_nested_set :scope => :group_id end I need to delete a group and all its "groupmessages" with it (using on the above ":dependent => :destroy"). But when I try to do it like this: Group.destroy(groupIdHere), I get the following error... ActiveRecord::RecordNotFound in GroupController#delete Couldn't find Groupmessage with ID=61 ...but the groupmessage with the ID=61 is definitely in the database! (Btw, it's a "child" groupmessage) Group.destroy(groupIdHere) works only if I delete "acts_as_nested_set ..." in the Groupmessage model. What can I do to make it work?? Thanks a lot for your help on this problem! Tom PS: below the end of the trace: . . . C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:80:in `transaction' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:100:in `transaction' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/transactions.rb:104:in `destroy' C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/base.rb:646:in `destroy' From lutzle at swbell.net Thu Apr 17 14:14:30 2008 From: lutzle at swbell.net (Larry E. Lutz) Date: Thu, 17 Apr 2008 13:14:30 -0500 Subject: [Betternestedset-talk] move_to_child_of in after_save Callback Message-ID: I'm trying to include a move_to_child_of in an after_save callback, but no matter how I do it, it seems to error out. Specifically, I've got a attribute named bns_parent_id in my model (and associated field in the table). I choose to create this field because I've been told that BNS does like it when you try to mess with it's reserved fields (parent_id, lft, and rgt). I have a field for bns_parent_id in my view (but not for parent_id). The I have the following in my model: def after_save(record) record.move_to_child_of record.bns_parent_id end I've tried multiple permutations of this callback, but they all seem to error out. Does anyone have any idea how to make this work? (By the way, it would be great if this or a similar type of functionality was incorporated into BetterNestedSet.) Larry E. Lutz lutzle at swbell.net -------------- next part -------------- A non-text attachment was scrubbed... Name: winmail.dat Type: application/ms-tnef Size: 8270 bytes Desc: not available Url : http://rubyforge.org/pipermail/betternestedset-talk/attachments/20080417/0651c2e5/attachment.bin From dontfall at gmail.com Thu Apr 17 14:49:21 2008 From: dontfall at gmail.com (Krishna Dole) Date: Thu, 17 Apr 2008 11:49:21 -0700 Subject: [Betternestedset-talk] move_to_child_of in after_save Callback In-Reply-To: References: Message-ID: <8d64b97d0804171149h66f808c6ic01583918155f859@mail.gmail.com> you may want to take a look at ez_set (one of the branches in the same svn repository). it does all the moving for you. k On Thu, Apr 17, 2008 at 11:14 AM, Larry E. Lutz wrote: > I'm trying to include a move_to_child_of in an after_save callback, but no > matter how I do it, it seems to error out. Specifically, I've got a > attribute named bns_parent_id in my model (and associated field in the > table). I choose to create this field because I've been told that BNS does > like it when you try to mess with it's reserved fields (parent_id, lft, and > rgt). I have a field for bns_parent_id in my view (but not for parent_id). > The I have the following in my model: > > > def after_save(record) > record.move_to_child_of record.bns_parent_id > end > > I've tried multiple permutations of this callback, but they all seem to > error out. Does anyone have any idea how to make this work? (By the way, it > would be great if this or a similar type of functionality was incorporated > into BetterNestedSet.) > > Larry E. Lutz > lutzle at swbell.net > > > > _______________________________________________ > Betternestedset-talk mailing list > Betternestedset-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/betternestedset-talk > > From sseago at redhat.com Tue Apr 22 10:32:44 2008 From: sseago at redhat.com (Scott Seago) Date: Tue, 22 Apr 2008 10:32:44 -0400 Subject: [Betternestedset-talk] Support for find options in queries (:include and :conditions, etc.) Message-ID: <480DF70C.10706@redhat.com> Has there been any work on supporting the various find options in the betternestedset methods. Right now there's no way to pass on, for example, the :include option to the find method to retrieve associations when calling API methods such as self_and_siblings, etc. I'd also like to be able to pass :conditions so that I can filter the results -- for example, my current nested set model also uses single table inheritance. I'd like to be able to return a list of siblings that is the same type as the current object. It looks like it would be relatively straightforward to handle a few specific use cases -- such as the above. I'd just have to modify the various API methods to accept an options arg, modify :conditions to include the nested set conditions bits, and pass it along to the find method. Scott From jc.michel at symetrie.com Wed Apr 23 08:48:08 2008 From: jc.michel at symetrie.com (Jean-Christophe Michel) Date: Wed, 23 Apr 2008 14:48:08 +0200 Subject: [Betternestedset-talk] Support for find options in queries (:include and :conditions, etc.) In-Reply-To: <480DF70C.10706@redhat.com> References: <480DF70C.10706@redhat.com> Message-ID: Hi Scott, Le 22 avr. 08 ? 16:32, Scott Seago a ?crit : > Has there been any work on supporting the various find options in the > betternestedset methods. Right now there's no way to pass on, for > example, the :include option to the find method to retrieve > associations > when calling API methods such as self_and_siblings, etc. I'd also like > to be able to pass :conditions so that I can filter the results -- for > example, my current nested set model also uses single table > inheritance. > I'd like to be able to return a list of siblings that is the same type > as the current object. > > It looks like it would be relatively straightforward to handle a few > specific use cases -- such as the above. I'd just have to modify the > various API methods to accept an options arg, modify :conditions to > include the nested set conditions bits, and pass it along to the find > method. Your contribution is welcome. You can either send a patch to the list or ask for a commit access on the svn repository, if you plan to add many features. Jean-Christophe Michel -- symetrie.com Better Nested Set for rails: http://opensource.symetrie.com/trac/better_nested_set From kevin at mopacmedia.com Wed Apr 30 22:56:21 2008 From: kevin at mopacmedia.com (Kevin Triplett) Date: Wed, 30 Apr 2008 21:56:21 -0500 Subject: [Betternestedset-talk] Update to move_to_tree Message-ID: <48193155.1030407@mopacmedia.com> Earlier, I pasted a pastie and had to update it. It's a function that moves a node and all its children from one tree to another. Here's the pastie link: http://pastie.caboo.se/189473 The earlier version had a bug which I fixed. It seems to be working in all the cases I've put it through. Kevin Triplett