Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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.


Comment on Re: Problem with table joins with Class::DBI
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://316884]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-09-19 09:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (133 votes), past polls