Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

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]
erix wonders what this question is really about: Best way to store/access large dataset?
[hippo]: Intriguing, isn't it?
[erix]: one would need the actuall query / queries
[erix]: he has obfuscated it effectively

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (10)
As of 2018-06-22 14:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (124 votes). Check out past polls.