belongs_to creates an presence validator to disable this you can do:

belongs_to :parent, self, :required => false,

or (untested):

belongs_to :parent, self, :auto_validations => false


--

Markus



On Sun, Oct 24, 2010 at 12:19:31PM -0700, DAZ wrote:
> Seems like dm-is-tree does all this and more, so best to use this....
> http://github.com/datamapper/dm-is-tree
> 
> DAZ
> 
> 
> 
> 
> On Oct 24, 5:57 pm, DAZ <[email protected]> wrote:
> > Hi,
> >
> > I'm trying to create some pages that can have child pages. Here is my
> > Page class:
> >
> > class Page
> >   include DataMapper::Resource
> >   property :id,             Serial
> >   property :title,          String, :required => true
> >   property :content,    Text
> >
> >   belongs_to  :parent,    self,   :key => true
> >   has n,      :children,  self,   :child_key => [:parent_id]
> > end
> >
> > I'm testing this in a console and getting the following:
> >
> > > test = Page.new
> >
> > => #<Page @id=nil @title=nil @content=nil @parent_id=nil>
> >
> > >test.title = "Test"
> >
> > => "Test"
> >
> > > test.children
> >
> > => []
> >
> > > test.parent
> >
> > => nil
> >
> > >test.save
> >
> > => false
> >
> > It all seems to be working fine, but won't save the page. Does anybody
> > have any ideas what I'm doing wrong here that is stopping it saving?
> >
> > cheers,
> >
> > DAZ
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "DataMapper" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/datamapper?hl=en.
> 

-- 
Markus Schirp
Phone:  049 201 / 647 59 63
Mobile: 049 163 / 824 80 69
Web:    www.seonic.net
Email:  [email protected]
Seonic IT-Systems GbR
Anton Shatalov & Markus Schirp
Altenessenerstraße 50
D-45141 Essen

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to