Take the 2-minute tour ×

So I have 2 models. Users and Groups. Each group has a user as the creator and a group has many users. The FK of these tables are set up correctly, but I was wondering if there was an easier way to get all related FK objects from other objects. For example, with a group object, is there a built in method to get the user object of the creator? Or for a user, is there a built in method to get all group object that he belongs to? I couldn't find out how to do this with the documentation on the symfony page. From what I see I feel like I need to create methods and use doctrine to access the appropriate tables using the current objects id and so on.


Some sample schema:

  actAs: { Timestampable: ~ }
    name: { type: string(500), notnull: true }
    image: { type: string(255) }
    type: { type: string(255), notnull: true }
    created_by_id: { type: integer }
    User: { onDelete: SET NULL, class: User, local: created_by_id, foreign: id, foreignAlias: groups_created }
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You need to show us your code for a decent answer, but it will be something like below.


        creator_id:     { type: integer(4), notnull: true }
        Creator:        { class: User, local: creator_id, foreign: id }


$user = $group->getCreator();
share|improve this answer
Thanks! so is there any part of the documentation that discusses how to use these "magic" methods? Also what if I wanted to change the way to call it. Instead of getCreatedBy(). Would I make some sort of alias or just another getter method that wraps it? Thanks again! –  Daniel Hertz Jun 1 '10 at 20:14
Sorry to bother you again. I am trying to access the creator by doing $this->getCreatedBy() and it doesn't work. Any ideas? –  Daniel Hertz Jun 1 '10 at 20:35
The method will be getCreator(), not getCreatedBy() –  Amy B Jun 1 '10 at 21:32
add comment

Your Answer


