views:

51

answers:

1

Hello folks,

I have a problem with the inheritance of Doctrine within my fixtures.yml file of Symfony.

Imagine the following:

NewsAuthor:
  inheritance:
    extends: sfGuardUser
    type:    simple

Now I want to declare the default guard user User_admin of the fixtures file of the sfDoctrineGuardPlugin to be the author of the first dummy article of my News model. But how to do this?

I tried the following:

NewsAuthor:
  AuthorAdmin:
    sfGuardUser: User_admin

But then I get this error of the doctrine:data-load task:

Unknown record property / related component "sfguarduser" on "NewsAuthor"

I use Symfony 1.4.8 with Doctrine 1.2.3.

Thank you in anticipation,
Lemmi

+1  A: 

You're misunderstanding how Doctrine's inheritance works. Under simple inheritance, NewsAuthor wouldn't have a reference to sfGuardUser, it would have all of the columns and relations that sfGuardUser has plus the ones you define. Inheritance is a bad approach here.

Instead, you want a NewsAuthor to have a reference to sfGuardUser. Your schema in this case would look like:

NewsAuthor:
  columns:
    user_id:
      type: integer(4)
      notnull: true
      unique: true #if one-to-one correspondence
  relations:
    User:
      class: sfGuardUser
      local: user_id
      foreignType: one

Your fixtures would then look as they did before:

NewsAuthor:
  AuthorAdmin:
    sfGuardUser: User_admin

You could then access the sfGuardUser object on a NewsAuthor object via $newsAuthor->User, similarly, you can access NewsAuthor on an sfGuardUser instance via $user->NewsAuthor.

jeremy
@jeremy Thank you for this well explained solution. But I don't understand what is Inheritance for?
Lemmi
It depends on the type of inheritance. I use concrete inheritance when I want to share methods across similar types that need to be in different tables. I use column_aggregation when the similar types will be retrieved concurrently.
jeremy