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/[email protected]/

Reply via email to