P is for Practical | |
PerlMonks |
Re: Class::DBI global questions and references (partly explained, waiting for more ;)by parasew (Beadle) |
on Sep 30, 2003 at 01:21 UTC ( [id://295156]=note: print w/replies, xml ) | Need Help?? |
ile, for having a good usage of Class::DBI, as far as i understood it you have to reference the classes the way you want to use them. this means that the has_a and has_many does not need to be the same as your references in the database. they are much more a tool to get the data in a way you want (Class::DBI is creating SQL queries, joins out of the has_a and has_many methods you define) if you need to get the entries from a user and vice versa, the best thing to do is to make has_many on both classes that need it. Class::DBI is very poor documented, at least the main parts are not clear since the underlying SQL-structure for the examples is not visible to the user, therefore issues like correct naming of Classes and database-tables become a problem (if you don't know how Class::DBI deals with that) i still didn't get the clue about how to use the Mapping described in the Class::DBI pod, and also still no clue about might_have. if anyone could describe me the both, i would be very happy :) at least i know how to use has_a and has_many correctly (at least i think so, any hints and better ways very welcome ;) has_a (1:1 - "one to one") for that, the naming is very important. this means your packages have to have the same name as the database tables. here is an example if every user could just have one role (i dropped the lookup table since it is not required for this example)
from the calling script you would go like: # test.pl
has_many (1:m - "one to many") for this, naming is not so important. that means for the same example as above, with a one-to-many relation, this would look like this MyPackageO2M.pm
from the calling script you would here go like: test_onetomany.pl
-- and for your question about SQL-query logging: i had the same problem and helped myself by enabling the log functionality from mysqld. the nice thing is that you can see all the queries sent to the server. i use it on a terminal-window with 'tail -f logfilename' which is a very comfortable solution. (works with the apache error.log also and is very nice to use for cgi/mod_perl development ;)
In Section
Seekers of Perl Wisdom
|
|