Welcome Guest, Not a member yet? Register   Sign In
DataMapper: Retrieve user/profile properties
#1

[eluser]xonorageous[/eluser]
Hi,

I'm working on a project with a group of people at university, and am in charge of the web side of the project.
Another group of people have set up the database but it doesn't use standard names (table name as a pluriel, etc.)

To make requests to the database I've set up the DataMapper ORM. My problem is that two tables as so:

Code:
USER: [IDUSER] [LOGIN] [PASSWD] [FIRST_NAME] [LAST_NAME] [IDPROFILE]
PROFILE: [IDPROFILE][NAME_PROFILE]

I would like to retrieve the profile name using the ID I have got in the user table.

For the moment I've got the following models:
user.php:
Code:
<?php
class User extends DataMapper
{
        var $table = 'user';
var $has_one = array( 'profile' );


function __construct( $id = null )
{
  parent::__construct( $id );
}


function login()
{
  $u = new Utilisateur;
  $u->where( array( 'login' => $this->login, 'passwd' => $this->passwd ) )
      ->get();
  $u->profile->get();
  dump( $u->profile->NAME_PROFILE );
  exit();
}

profile.php
Code:
<?php
class Profil extends DataMapper
{
var $table = 'profile';
var $has_many = array( 'user' );
}

In user.php the dump of $user->profile->NAME_PROFILE is returning null. How can I configure the request to pass in field names as well as the table name?

Thanks in advance




Theme © iAndrew 2016 - Forum software by © MyBB