(naming conventions)++ mine is id_tablename for the pk, fk_foreigntablename for fk's and rel_foreigntablename for the dbic relationships. I changed my relnames to something else than the columnnames very soon after starting to use dbic to no have to use get_column and to be able to see easily if I call a value or a foreign object. Never regretted it.
-Alex > -----Original Message----- > From: Nilson Santos Figueiredo Junior [mailto:[EMAIL PROTECTED] > Sent: Saturday, January 20, 2007 5:51 PM > To: [email protected] > Subject: Re: [Dbix-class] doing a search > > On 1/20/07, Jess Robinson <[EMAIL PROTECTED]> wrote: > > Instead of changing the relationships, you can also still get at the > > original data, by using get_column. In your example beore, > > $role->get_column('id_role') should output what you wanted. (Or > > $role->id_role->id) > > Of course, but using the default relationship names you either get > crappy names for your relationships (e.g. "role_id" instead of "role") > or you get crappy names for your database fields (e.g. a field called > "role", when it stores the role id). > > The best way IMO is to have the field named "role_id" then name your > relationship as "role". > > This way, when you call $user->role you get the object and when you > call $user->role_id you get the id. This way you can avoid extra > queries or prefetches in some cases and there's no need to use the > much more verbose $user->get_column('role'). Using get_column() > instead of named accessors also makes it more difficult if you ever > end up doing a lot of subclassing: instead of overriding a single > method, you'll need to override the generic get_column() and then act > accordingly. > > -Nilson Santos F. Jr. > > _______________________________________________ > List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class > Wiki: http://dbix-class.shadowcatsystems.co.uk/ > IRC: irc.perl.org#dbix-class > SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/ > Searchable Archive: http://www.mail-archive.com/dbix- > [EMAIL PROTECTED]/ *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien Handelsgericht Wien, FN 79340b *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* Notice: This e-mail contains information that is confidential and may be privileged. If you are not the intended recipient, please notify the sender and then delete this e-mail immediately. *"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"* _______________________________________________ List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class Wiki: http://dbix-class.shadowcatsystems.co.uk/ IRC: irc.perl.org#dbix-class SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/ Searchable Archive: http://www.mail-archive.com/[email protected]/
