0

I'm struggling with the connection/relation from the main class/table to a related class in symfony 1.4 with doctrine. The relation is

$relatedClass->identifier == 'e'.$mainClass->id;

I know that I could realise it easily without this prefix but I am working with an existing database and existing subcomponent, so I can't change this relation.

Any ideas? Thanks!

4

2 回答 2

1

You cannot implement this is a relation in Doctrine because it is not a true foreign key.

If you cannot change the existing column, is it possible to create a new column? If so, write a migration to add a column to the relatedClass table with a proper foreign key relationship.

于 2011-08-23T01:43:59.713 回答
0

I finally made a 'pseudo relation' like this:

$results = Doctrine::getTable($relatedClass)
            ->createQuery('alias')
            ->addWhere('alias.identifier=?','e'.$event->getId())
            ->execute();

It has several advantages:

  • no changes of the existing tables necessary
  • no adding of a useless column to a already huge database

It is not elegant but it is the solution with the most advantages so far.

于 2011-08-23T02:28:24.187 回答