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/is/tree.rb
(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 at 
http://groups.google.com/group/datamapper?hl=en.


Reply via email to