Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

tmtm (2563)

  (email not shown publicly)

Journal of tmtm (2563)

Saturday December 15, 2001
07:03 PM

The Great Class::DBI Clean Up

[ #1669 ]

The great Class::DBI clean up continues.

Today I pulled about 150 lines out of the main module into a support module. This was pretty hairy as it was the code that handled all the 'relationships' between classes - which is pretty important stuff for a module that handles database mappings!

I originally attempted to do this via mixins - basically just exporting all the methods I needed. But some of the methods over in Class::DBI proper needed to play with all the relationship data too, so I ended up exporting almost every method, including supposedly 'private' ones, which is always a worrying sign.

Thankfully the hooks I'd added when I was writing the Class::DBI::mysql::FullTextSearch module proved their worth. So I was able to take code, such as that for cascading delete, which needed to follow the relationship path, and implemented it trivially in the helper module just registering a delete hook.

Unfortunately, the other major point in Class::DBI where standard behaviour changes if there are relationships is create(). If you try to create with a field set to a related object rather than just its id
  CD->create({ title => $title, artist => $artist })
instead of
  CD->create({ title => $title, artist => $artist->id })
then it needs to DWIM. And we have no pre_create hook as there is no object at that point we can play with :(

For now, I've just implemented a _tidy_creation_data method which does nothing in Class::DBI proper, but which gets overridden when you set up a relationship to one that downgrades embedded objects to their ids.

I don't like this though, and I need to find a better way ...

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.