Hi, Martin, I notice that `child_key` issue isn't resolved yet. I think the following statement is not necessary when using dm-is- tree: property :parent_id, Integer
because ideally dm-is-tree generates it by default. and if we want change to another child_key, we can do this: is :tree, :child_key => 'other_column_name' by far, in dm-is-tree implementation, `is_tree` method evaluates the following code: belongs_to ... has n, ... but it does NOT evaluate: property options[:child_key], Integer so, we can't write code like this: SomeModel.all(:parent_id => 345) instead, we should do this: SomeModel.all(:parent => SomeModel.get(345)) That's a little annoying, and this issue affects `roots` and `first_root`: def roots options = { tree_options[:child_key] => nil } options = { :order => Array(tree_options[:order]) }.merge (options) if tree_options[:order] all options end def first_root options = { tree_options[:child_key] => nil } options = { :order => Array(tree_options[:order]) }.merge (options) if tree_options[:order] first options end Two approch: 1. evaluate in is_tree: property options[:child_key], Integer, :required => false or 2. change roots and first_root criteria to: options = { tree_options[:parent] => nil } I can't tell which is the best. Thanks for your work, Martin. On Jan 25, 4:24 am, sliu <liusong1...@gmail.com> wrote: > Thanks and Cheers! > > On Jan 21, 1:32 pm, Martin Gamsjaeger <gamsnj...@gmail.com> wrote: > > > Hey, > > > I just pushed a fix for this to dm-is-tree. Thx for finding this and > > sharing! > > >http://github.com/datamapper/dm-more/commit/db424c34cc20349c640e2f3d9... > > > cheers > > snusnu > > > On Thu, Jan 21, 2010 at 12:57, sliu <liusong1...@gmail.com> wrote: > > > Because I didn't declare :parent_id property(is :tree genereates it > > > implicitily), so > > > >http://github.com/drove/dm-more/blob/master/dm-is-tree/lib/dm-is-tree... > > > > Line 95: > > > options = { tree_options[:child_key] => nil } > > > > should be changed to: > > > > options = { :parent => nil } > > > > On Jan 21, 11:48 am, sliu <liusong1...@gmail.com> wrote: > > >> My previous post can resolve the "NOT NULL restriction issue" using an > > >> explict :required => false option, but bring another issue. > > >> Since :required option is only accepted by belongs_to, not has n. > > >> So the two line I mentioned above should be modified > > >> as:http://github.com/drove/dm-more/blob/master/dm-is-tree/lib/dm-is-tree... > > >> (L74-L75) > > > >> assc_options = { :model => options[:model], :child_key => Array > > >> (options[:child_key])} > > >> has_n_options = options[:order] ? { :order => Array(options > > >> [:order]) }.merge(assc_options) : assc_options.dup > > >> assc_options.update(:required => false) > > > >> belongs_to :parent, assc_options > > >> has n, :children, has_n_options > > > >> note: assign assc_options.dup to has_n_options, and update :required > > >> => false option in the last line. > > > >> On Jan 15, 5:25 am, sliu <liusong1...@gmail.com> wrote: > > > >> > Save a root in dm-is-tree yield an validation error: > > > >> > @errors={:parent_id=>["Parent must not be blank"]} > > > >> > that's because root(s) node parent_id is NULL, but dm-is-tree calls > > >> > "belongs_to :parent" doesn't carry :required => false option. > > > >> >http://github.com/drove/dm-more/blob/master/dm-is-tree/lib/dm-is-tree... > > > >> > assc_options = { :model => options[:model], :child_key => Array(options > > >> > [:child_key]) } > > >> > should be: > > >> > assc_options = { :model => options[:model], :child_key => Array(options > > >> > [:child_key]) , :required => false} > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "DataMapper" group. > > > To post to this group, send email to datamap...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > datamapper+unsubscr...@googlegroups.com. > > > For more options, visit this group > > > athttp://groups.google.com/group/datamapper?hl=en. -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to datamap...@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.