I am trying to achieve something that should be simple but seems impossible in PHP ActiveRecord.
In the simplified example I created, I have two models, Person and Exchange, and two tables, people(id, name) and exchange(id, user_from_id, user_to_id, comment). exchange.user_from_id and exchange.user_to_id have a foreign key constraint referencing people.id.
So when I run the following code:
$exchange = Exchange::first();
echo $exchange->user_from_id;
echo $exchange->user_from_id->name;
I would expect the first echo to fail and the second one to succeed. Instead, the first one succeeds and prints the litteral value of exchange.user_from_id and then obviously the second one generates a "Trying to get property of non-object" warning.
The result is the same with or without adding the following to Exchange:
static $belongs_to = array(
array('user_from_id', 'class_name' => 'Person'),
array('user_to_id', 'class_name' => 'Person')
);
What should I change in my code to make it so that $exchange->user_from_id returns an instance of the Person class?