Welcome Guest, Not a member yet? Register   Sign In
How to represent this relationship in DataMapper
#3

[eluser]papercut[/eluser]
I did that.

Here's how I defined them:

models/session.php
Code:
class Session extends DataMapper {
var $has_many = array('track', 'user');
var $has_one = array('author' => array('class' => 'user', 'other_field' => 'authored'));
}

models/user.php
Code:
class User extends DataMapper {
var $has_many = array('track', 'user', 'authored' => array('class' => 'session', 'other_field' => 'author'));
}

controllers/test.php
Code:
$s->author->get();
echo("Author name: " . $s->author->name . "<br>");
echo("Author e-mail: " . $s->author->email . "<br>");

And this is the error message:

Quote:Error Number: 1054

Unknown column 'authored_sessions_users.authored_id' in 'where clause'

SELECT `users`.* FROM (`users`) LEFT OUTER JOIN `sessions_users` authored_sessions_users ON `users`.`id` = `authored_sessions_users`.`author_id` WHERE `authored_sessions_users`.`authored_id` = 2

I have tried to do this in many different ways. I've also tried to specify the foreign-key names, etc.

Thanks for your reply!

EDIT: This is weird because I just tried to output information about the author (the one-to-many part), so it shouldn't go to the join table, sessions_users. Right?


Messages In This Thread
How to represent this relationship in DataMapper - by El Forum - 08-17-2013, 03:28 PM
How to represent this relationship in DataMapper - by El Forum - 08-17-2013, 03:49 PM
How to represent this relationship in DataMapper - by El Forum - 08-17-2013, 04:00 PM
How to represent this relationship in DataMapper - by El Forum - 08-18-2013, 06:57 AM
How to represent this relationship in DataMapper - by El Forum - 08-18-2013, 09:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB