Bug or misunderstanding?

20 views
Skip to first unread message

Dennis Haarbrink

unread,
May 23, 2013, 3:45:30 AM5/23/13
to redbe...@googlegroups.com
In the documentation on aliases it says:

Aliased Lists (3.3+)
To get a list of all projects associated with a certain person, in the role of a student (aliased as student) use:

    $person->alias('student')->ownProject;

But when I test my installation (composer installed -> 3.4.4):

list($point1, $point2, $point3) = R::dispense('point', 3);
$point1->x = 1; $point1->y = 1;
$point2->x = 2; $point2->y = 2;
$point3->x = 3; $point3->y = 3;

$list = R::dispense('list');
$list->ownDifference = array($point1, $point2, $point3);

$id = R::store($list);
$list = R::load('list', $id);

var_dump(count($list->alias('point')->ownDifference));


The result is '0'.

When I instead use 'ownPoint', it results in the expected '3'.


I am not sure if it's a bug or just a misunderstanding from my part.


Cheers,
Dennis

gabor

unread,
May 23, 2013, 3:26:12 PM5/23/13
to redbe...@googlegroups.com

Hi,

Aliased lists are meant to retrieve lists based on an aliased bean (column).
This is a 1-to-X relation where X can be any exact number, for instance 2.

Let's say we have lines and each line has exactly two points A and B.
Now we could use $line->ownPoint but since we know we need exactly 2 we can also call them: pointA and pointB.
However, while they are called pointA and pointB they still are 'points'.

Now we can see which lines cross point A using:

$a->alias('point_a')->ownLine

Full example:

$points = R::dispense('point', 2);
$line = R::dispense('line');
$line->pointA = $points[0];
$line->pointB = $points[1];
R::store($line);
$line2 = R::dispense('line');
$line2->pointA = $line->pointA;
$line2->pointB = R::dispense('point');
R::store($line2);
//now we have two points per line (1-to-x)
//I want to know which lines cross A:
$a = R::load('point', $line->pointA->id); //reload A
print_r($a->alias('point_a')->ownLine);

cheers,
Gabor
Reply all
Reply to author
Forward
0 new messages