[CDBI] Class::DBI data serialization

Thomas Charron twaffle at gmail.com
Tue Feb 6 22:01:33 GMT 2007

  I've been using Class::DBI for a while now, but I've finally hit a
snag where I need to serialize the Class::DBI objects to JSON strings
for a web client to use.

  The perl JSON module doesn't handle Class::DBI nicely at all, so
I've wrapped my own to emit the JSON formatted data, which is working

  Here's the catch.  The data I have in my database pretty much, in
one way or another, references everything.  Example:

User <-> Player

  When I serialize the User object, I in turn ask the Event objects to
serialize themselves, as well as the Player object, but they, in turn,
ask the User module objects to serialize themselves, which in turn ask
the Event Objects to serialize themselves, etc..etc..

  Is there any way for me to compare what each module is pointing to
without doing a textual comparison?  Since the User module uses a
primary of 'id', and Event uses 'user_id', I can't do a simple
comparison, but I can't seem to find a way to access the 'type'
information of a given column name.  Since JSON allows me to create
objects, if a column type points to the type of the parent, I could
say I don't care about it, since I can infer it points back to me as
it's foreign key.

  Guess That's another way to look at it.  Can I get the foreign key
information from a Class::DBI object from the column name?

  Sorry if this seems obtuse, just been looking at it for hours now,
and I can't seem to find a way to get at this information.

-- Thomas

More information about the ClassDBI mailing list