| 
      
      
      From: Chris W. <ch...@cw...> - 2001-12-18 16:25:06
      
     | 
| * John Sequeira (js...@me...) [011218 11:09]:
> I'm trying to create a has_a relationship between one of my classes and the
> OpenInteractive::User class.
> ... 
> Then I changed it to
> 
> 	      has_a        => { 'OpenInteract::User' => [ 'user_id' ], },
> 
> and apache was happy,  but now I'm not sure how to reference the object.
> 
> I had thought $myobj->{user}->{login_name} would work,  but it does not.
> 
> I thought I followed the simple case mentioned in the 'has_a' docs,
> and although the there's example code in User->>Theme I couldn't
> find anything helpful.
Almost there, you should be able to use:
  $myobj->user->{login_name};
The 'has_a' creates a method called 'user' (rather than a property, as
you were trying to access) that retrieves the relevant user object for
you.
Note that it's probably safer to do something like:
 my $user = $myobj->user;
 my $login_name = ( $user ) ? $user->{login_name} : 'Anonymous';
just in case $myobj doesn't have 'user_id' defined.
Note: Object relationships are getting rewritten, but it will
(hopefully) have much the same interface.
Chris
-- 
Chris Winters (ch...@cw...)
Building enterprise-capable snack solutions since 1988.
 |