[Dbix-class] table referencing itself
John Napiorkowski
jjn1056 at yahoo.com
Wed Dec 20 22:21:07 GMT 2006
--- Brandon Black <blblack at gmail.com> wrote:
> On 12/20/06, Daniel McBrearty
> <danielmcbrearty at gmail.com> wrote:
> > Is there a way to get the id of the object being
> created in the
> > statement doing the creation? I don't even know if
> the db (postgresql)
> > can do that ... ?
> >
>
> AFAIK, postgres doesn't support doing this easily
> for an autogenerated
> SERIAL column.
>
> This type of statement does work however:
>
> insert into whatever values
> (nextval('public.tree_nodeid_seq'::text),
> currval('public.tree_nodeid_seq'::text), .....);
>
> Of course, if you really are making a tree or graph,
> and
> self-reference is just a way to say "root-level
> node", I'd say just
> make it nullable and treat nulls as root-level nodes
> and have an
> easier life.
I would have to agree with this sentiment. I have a
number of self-referencing tables and trying to make
the FK not null is a serious hassle. I found it
greatly complicated even basic development tasks, like
creating triggers for no particular gain. So unless
you have a really compelling business need to do it
the way you've outlined I would recommend against it.
--john
>
> -- Brandon
>
> _______________________________________________
> List:
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
>
http://www.mail-archive.com/dbix-class@lists.rawmode.org/
>
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the Dbix-class
mailing list