Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Problem with table joins with Class::DBI

by perrin (Chancellor)
on Dec 24, 2003 at 16:30 UTC ( #316884=note: print w/replies, xml ) Need Help??

in reply to Problem with table joins with Class::DBI

Class::DBI doesn't directly handle this situation, partly because it isn't clear how what you are doing should translate into objects. You have a reporting query which brings back a mix of fields from three tables. What class of object should you end up with?

One way to do it is to use Class::DBI::View. That lets you use arbitrary SQL queries and get back a list of objects that correspond to rows, although they are not editable.

Another approach would be to break this down into objects and relationships. If you select a task, you should be able to call $task->employee() or something similar to get an employee object, and $task->status() to get a status object. This is more how Class::DBI is intended to be used.

As for the ordering, you can do that in perl, e.g. sort by $task->employee()->lname(). If you need to do it in the database, you can create multiple constructors in your Task class, using the set_sql() method to allow them to join other tables. Set up one of these for each possible sort and then call the appropriate one.

There are other approaches, but hopefully that will get you started.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://316884]
and the monastery is silent...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2018-03-24 13:00 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (298 votes). Check out past polls.