Welcome Guest, Not a member yet? Register   Sign In
DataMapper stumping me - almost works
#1

[eluser]BrianDHall[/eluser]
Hi all,

I'm using DataMapper (OverZealous Extension) and am running into something that I'm just not getting.

I have a table for listings, and a table for garagetypes, with a relationship of has_one from listings to garagetypes, and has_many the other way around.

Here's the code in question:

Code:
$li = new Listing();
$li->where('id', 1)->get();
$li->garagetype->get();

So I get the listing with an ID of 1 - this works as expected. What I can't get to work is the last line.

If I build my table with a join table of garagetypes_listings, DataMapper will correctly update that table correctly referencing the listing and the garage type that corresponds to it. If I build my table without a join table and instead use an in-table foreign key of garagetype_id, that works as far as the saving of the relationship as well.

What doesn't work at all, no matter what I do, is the 3rd line of code. I turned on profiling and I get this for SQL queries:

Code:
DATABASE:  rentlist   QUERIES: 3
SELECT * FROM `listings` LIMIT 1  
SELECT * FROM (`listings`) WHERE `id` = 1
SELECT * FROM `garagetypes` LIMIT 1

OK, so each query relates to each line of code, right?

What I'm not getting is why the third line of code is what it is, or acts like it does.

According to my debugger after that third line of code $li has a garagetype object, which has values of null as far as id and name and display name go. Garagetype table has 6 entries, and the join table (when used) shows id 0, garagetype_id 2, and listing_id 1.

I don't get it - what am I missing? Where to look next?

There seems to be something fundamental I'm missing here, I just have no idea what it is.


Messages In This Thread
DataMapper stumping me - almost works - by El Forum - 09-03-2009, 01:52 PM
DataMapper stumping me - almost works - by El Forum - 09-03-2009, 02:16 PM
DataMapper stumping me - almost works - by El Forum - 09-03-2009, 04:13 PM
DataMapper stumping me - almost works - by El Forum - 09-04-2009, 12:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB