What's wrong with this DataMapper code? |
[eluser]Unknown[/eluser]
I've stared at it until my eyes hurt (literally) and I can't figure this one out. This uses DataMapper, and I'm trying to create a new Bookmark associated with the User. I've done this more times than I can count in the past, but today... In my Controller's __construct() I have this, because I use "the current user" often enough that this makes sense: Code: $this->whoami = new User(); And in one of the methods, I have this: Code: $b = new Bookmark(); The result is always that the Bookmark entry is created in the "bookmarks" table, but no entry is created in the "users_bookmarks" table (nor bookmarks_users if I name it that). There's no errors, no warning, just a Bookmark not associated to a User. The classes are really vanilla, not even methods. Here they are: Code: class User extends DataMapper { Code: class Bookmark extends DataMapper { The tables are very simple as well: users -- id, email, password bookmarks -- id, lon, lat, title, description users_bookmarks -- id, bookmark_id, user_id What I have tried: * Replacing $b->save($this->whoami) with $this->whoami->save($b) to no effect. * Renaming users_bookmarks to bookmarks_users * Not using a 'id' column in users_bookmarks Probably something really simple, but it's getting late and I've already spent over 2 hours poring over these same 30 lines of code.
[eluser]ntheorist[/eluser]
perhaps in your method try a more straightforward Code: $b->save(); are you sure that $this->whoami always retrieves a result? checking if($this->whoami->exists()) for instance.. relationships need both models to have non-null ids also turn your output profiler on, what queries is it generating? plus which version of datamapper are you using? _n_
[eluser]Unknown[/eluser]
[quote author="ntheorist" date="1267810430"]perhaps in your method try a more straightforward Code: $b->save(); Yeah, did that as per my older code. Nada. But, I switched over to DataMapper OverZealous anyway, as I wanted to dispense with the joining table. And then it worked. [quote author="ntheorist" date="1267810430"]are you sure that $this->whoami always retrieves a result? [/quote] Yep, positive. Other code already checked $this->whoami->id and exited (not logged in) a while ago. [quote author="ntheorist" date="1267810430"]also turn your output profiler on, what queries is it generating?/quote] A profiler? That will show me actual queries? Please tell me more! I have missed that more than any other potential feature!
[eluser]ntheorist[/eluser]
Quote:A profiler? That will show me actual queries? Please tell me more! I have missed that more than any other potential feature! hehe for a sec i thought u were being sarcastic just set $this->output->enable_profiler(TRUE); typically in your controller's constructor. see http://ellislab.com/codeigniter/user-gui...iling.html gl, n |
Welcome Guest, Not a member yet? Register Sign In |