CodeIgniter Forums
Datamapper relationship problems - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Datamapper relationship problems (/showthread.php?tid=16715)



Datamapper relationship problems - El Forum - 03-14-2009

[eluser]Iverson[/eluser]
I have three models with the following relationships:

Code:
//Poll.php
var $has_many = array('poll_answer');

//Poll_answer.php
var $has_many = array('poll_vote');

//Poll_vote.php
var $has_one = array('poll_answer');

When I save a vote, the relationships get added fine. However this doesn't return anything at all:

Code:
$p->get_by_id($id);
$p->poll_answer->get();
$p->poll_answer->poll_vote->get();

No clue...


Datamapper relationship problems - El Forum - 03-22-2009

[eluser]OverZealous[/eluser]
Iverson,

Did you ever get this working?

In your example, you need to have a has_one or has_many in poll_answer for poll. You always need to have both sides of every relationship.

Otherwise, you haven't provided too much to go on here. Try turning on profiling, and checking the SQL queries. See if something is out of place. Run the queries directly on your DB to see what you get. Make sure you get a result for the second line ($p->poll_answer).


Datamapper relationship problems - El Forum - 03-23-2009

[eluser]Iverson[/eluser]
[quote author="OverZealous.com" date="1237795004"]Iverson,

Did you ever get this working?

In your example, you need to have a has_one or has_many in poll_answer for poll. You always need to have both sides of every relationship.

Otherwise, you haven't provided too much to go on here. Try turning on profiling, and checking the SQL queries. See if something is out of place. Run the queries directly on your DB to see what you get. Make sure you get a result for the second line ($p->poll_answer).[/quote]

How did I miss that? :-S