Datamapper: Get last id & relationship stuffs - 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: Get last id & relationship stuffs (/showthread.php?tid=47932) |
Datamapper: Get last id & relationship stuffs - El Forum - 12-28-2011 [eluser]scherman[/eluser] Hi, i want to split this topic in three parts (everything about datamapper): Part 1: How can i do to get the id i've just inserted? With this code, it doesn't work: Code: $image = new Image(); It returns 0 ______________ Part 2: I have two classes: Post and Image. Each Post can has one image, and each image can belong to many posts. But i want that the image's post can add after create the post. For example, i am writing a post, but i am not finish yet, so i save it, and i will finish at the future. My problem is that i don't know how to change the model to set the image as optional, and not required. There is my post's class (only the image's part): Code: class Post extends DataMapper { But when i want to save the post with the image ($post->save($image)), it returns me some strange errors (only put the one i consider the key to solve the problem): Quote:An Error Was Encountered ______________ Part 3: Which is the difference between the save() and the save_as_new()? Because i had an error, and i didn't know how to fix it, and i try change save() to save_as_new, and it worked. I wanted to save a new object, anything more. I hope you can help me |