Propel icon indicating copy to clipboard operation
Propel copied to clipboard

Autoload problems with some entities

Open darkoromanov opened this issue 9 years ago • 3 comments

Hi,

I have a weird problem with autoload. I placed this configuration in my composer.json:

"autoload": {
    "classmap": ["generated-classes/"]
  }

it works with some entities, for example, I have a MySQL table called instances and when I instantiate the classes:

$a = new Instance();
$a = new InstanceQuery();
$a = new \Map\InstanceTableMap();

it correctly works. But I get errors when I try to do the same with entity ShortText:

$a = new ShortText();
$a = new ShortTextQuery();
$a = new \Map\ShortTextTableMap();

Fatal error: Class 'ShortText' not found in /Applications/XAMPP/xamppfiles/htdocs/morpho/admin/index.php on line 12

This is the schema of ShortText:

<table name="values_short_text" phpName="ShortText">
        <column name="instance_id" type="integer" required="true" primaryKey="true"  />
        <column name="field_code" size="255" type="varchar" required="true" primaryKey="true"  />
        <column name="value" size="4000" type="varchar" />
        <foreign-key foreignTable="instances" phpName="Instance" refPhpName="ShortText">
            <reference local="instance_id" foreign="id"/>
        </foreign-key>
</table>

If I manually include the files it works fine:

include "generated-classes/Base/ShortText.php";
include "generated-classes/Base/ShortTextQuery.php";
include "generated-classes/ShortText.php";
include "generated-classes/ShortTextQuery.php";
include "generated-classes/Map/ShortTextTableMap.php";

So the current workaround I'm using is:

    foreach (glob("generated-classes/Map/*.php") as $c) {
        require_once $c;
    }
    foreach (glob("generated-classes/Base/*.php") as $c) {
        require_once $c;
    }
    foreach (glob("generated-classes/*.php") as $c) {
        require_once $c;
    }

darkoromanov avatar Mar 16 '15 09:03 darkoromanov

Can you check the generated Model classes namespaces ?

Maxooo avatar Mar 16 '15 11:03 Maxooo

Sure, I'll paste the files:

<?php

use Base\ShortText as BaseShortText;

/**
 * Skeleton subclass for representing a row from the 'values_short_text' table.
 *
 *
 *
 * You should add additional methods to this class to meet the
 * application requirements.  This class will only be generated as
 * long as it does not already exist in the output directory.
 *
 */
class ShortText extends BaseShortText
{

}
<?php

use Base\Instance as BaseInstance;

/**
 * Skeleton subclass for representing a row from the 'instances' table.
 *
 *
 *
 * You should add additional methods to this class to meet the
 * application requirements.  This class will only be generated as
 * long as it does not already exist in the output directory.
 *
 */
class Instance extends BaseInstance
{

}

The namespace inside Base and Map seems all correct, they're all like the ones of Instance entity which works. The problem is with all the entities related to tables starting with values_ I have many of them and all have the same problem.

darkoromanov avatar Mar 16 '15 12:03 darkoromanov

Experience the same problem. From some time new added tables' classes are not found although they do exist in generated classed directory.

UPD: I added before to composer.json:

    "psr-0": {
        "Myclasses\\": "myclasses"
    }

And after that code outside App in Slim Framework stopped to work. Removed this and run "composer update", now new classes work well. So my mistake. Maybe will be useful

NatalyaSidun avatar Nov 08 '18 10:11 NatalyaSidun