Ticket #683 (closed defect: fixed)

Opened 19 months ago

Last modified 16 months ago

[sfDoctrine] Column agregation - setSublcasses() causes Segmentation faults

Reported by: adrive Owned by: zYne-
Priority: major Milestone: 2.0.0 (OLD)
Component: Other Version:
Severity: Keywords:
Cc: jackbravo Has Test:
Status: Has Patch:

Description

Column aggregation works fine, but not in symfony project. After some self investigatings i did'n found something, that should cause segmentation faults. Maybe that's because I didn't understand well the core of doctrine internals.

I thought, that I have problem with php-5.2.0 on debian etch, later with php-5.2.3 on lenny, but I also compile php-5.2.5 myself, but segfault still occures.

I'll assume, you already have some symofny project with sfDoctrinePlugin and database configured correctly.

Here is simple schema.yml you will need to generate test models:

$ cat config/doctrine/schema.yml
Entity:
  tableName: node
  columns:
    name:
      type: varchar
      size: 20
    # used for column aggregation
    type:
      type: integer
      size: 11

User:
  inheritance:
    extends:  Entity
    keyField: type
    keyValue: 1

Group:
  inheritance:
    extends:  Entity
    keyField: type
    keyValue: 2

$ symfony doctrine-build-model
>> doctrine  Generated models successfully

Now there are three generated models - Entity, User, Group in lib/models/doctrine/generated. The base class for User looks like this:

abstract class BaseUser extends Entity
{
  public function setTableDefinition()
  {
    parent::setTableDefinition();
  }

  public function setUp()
  {
    parent::setUp();
    $this->setInheritanceMap(array('type' => '1'));
  }
}

This is fine, and inheritance should work, but without Column agregation. If I select from Entity, I do not have User and Group instances in collection, but instances of Entity

For working column aggregation I need to define child classes to parent class via subclasses method.

So I edit user model in lib/models/doctrine/Entity.class.php to look like this:

class Entity extends BaseEntity
{
  public function setTableDefinition()
  {
    parent::setTableDefinition();

    $this->setSubclasses(array(
      'User' => array('type'=> 1),
      'Group' => array('type'=>2),
    ));
  }
}

Now in some action try to create your first record (symfony module yourapp yourmodule;cd apps/yourapp/modules/yourmodule).

$ cat actions/actions.class.php
class testActions extends sfActions
{
  public function executeIndex()
  {
    $user = new User();
    $user->name = 'adrive';
    $user->save();
  }
}

Now when you execute your action you will find in your apache error log notice about segfault

$ tail /var/log/apache2/error.log
...
[Mon Dec 17 16:29:43 2007] [notice] child pid 14609 exit signal Segmentation fault (11)

I try this on latest sfDoctrine (6540) with Doctrine (3279) and PHP versions mentioned above PHP 5.2.0-8+etch7, PHP 5.2.3-1+b1 (Lenny), and custom PHP 5.2.5 on Lenny.

Change History

Changed 19 months ago by jackbravo

Indeed its a bug on the setSubclasses method. I've bumped into this before.

Not sure where it happens, but its because you aren't defining ALL BaseEntity? subclasses on the setSubclasses method. As a workaround, if you change it to:

    $this->setSubclasses(array(
      'Entity' => array('type' => 0),
      'User' => array('type'=> 1),
      'Group' => array('type'=>2),
    ));

it should work.

Changed 19 months ago by jackbravo

  • owner changed from jwage to somebody
  • component changed from sfDoctrine to general

Changed 19 months ago by jackbravo

  • cc jackbravo added

Changed 19 months ago by adrive

  • priority changed from minor to major

First of all thank you for solving my first problem - creating records. But this isn't fix for column aggregation problem. Now when i want to query all entities it queries only type = 0 records. SELECT e.id AS e__id, e.name AS e__name, e.type AS e__type FROM entity e WHERE (e.type = 0) But I want to `Doctrine_Query::create()->from('Entity')->execute() get also Users and Groups.

I read also Ticket #615. I placed my  comment there with example of symfony like class inheritance which work fine whithout necessity to put all extending classes into subclasses array.

I don't think this is general problem, but symfony related problem, because without symfony environment and sfDoctrine - only on pure doctrine column aggregation works fine.

Changed 19 months ago by jackbravo

It is more common to get this type of scenarios in sfDoctrine, but if you create a similar inheritance structure using just Doctrine you'll bump into the same problem.

I see your point on the querying issue. Still as a workaround you could fetch for BaseEntity?. But this is still a bug that I hope it can be solved because I have the same problem right now.

Changed 19 months ago by adrive

No, when I fetch BaseEntity? I see two problems - first is that BaseEntity? is generated as abstract class which cannot be instantiated and the second problem is that if I make it general class and query BaseEntities?, column aggregation don't work.

I have already created similar inheritance structure only in Doctrine, and it works as I am expecting.

Changed 19 months ago by jwage

  • owner changed from somebody to zYne-
  • milestone set to 1.0

This is the same as this ticket #678

I think this is a bug and you should be able to have abstract base classes and still be able to use the Doctrine inheritance features.

Changed 16 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [3960]) fixes #683

Changed 16 months ago by anonymous

  • milestone 1.0 deleted

Milestone 1.0 deleted

Note: See TracTickets for help on using tickets.