Need some help with Datamapper |
[eluser]mvdg27[/eluser]
Hi guys, I just started using Datamapper (WanWizard version). I've read through all the documentation (well, almost everything) and tried some examples. So far I think I get the concept. Now while trying my first real-life application, I can't get it to work exactly as intended. Basically I have this (simplified) situation: 1) I have users for my application. They are stored in a simple table (id, username, password) 2) I have projects (id, name and description) 3) When a project is created, it must be linked to the user that created the project, the owner so to speak (= the logged in user) 4) More than 1 user can be assigned as a member of the project. So far I made two models. Project and User, with the following relations: Code: class User extends DataMapper { Furthermore I've made a relations table with the following structure: id | owner_id | owner_project_id | member_id | member_project_id Now when I try to save a new project, the project get's saved, but no relationship is saved. Code: $oProject = new Project(); Clearly there is something wrong in my code. Can anyone point me in the right direction? Thanks in advance! Cheers, Michiel
[eluser]WanWizard[/eluser]
There are two mistakes in your code. 1. If you want to save a relationship, you will have to pass the object you want to relate. $oUser->owner is not an object, it's a property (and one that doesn't exist). 2. If you have multiple relations to the same table, you have to indicate which relation you're going to save. Code: // save the project, save the user as project owner Code: // save the project, save the user as project owner |
Welcome Guest, Not a member yet? Register Sign In |