[Dbix-class] doing a search

Nilson Santos Figueiredo Junior acid06 at gmail.com
Sat Jan 20 16:50:33 GMT 2007


On 1/20/07, Jess Robinson <castaway at desert-island.demon.co.uk> 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.



More information about the Dbix-class mailing list