spotorm / spot2

Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer
http://phpdatamapper.com
BSD 3-Clause "New" or "Revised" License
601 stars 101 forks source link

Wrong field type #237

Closed FlipEverything closed 6 years ago

FlipEverything commented 7 years ago

I'm experiencing a weird problem with my entities.

I have the following example entity definition:

class Content extends \Spot\Entity
{
  public static function fields()
  {
    return [
      'id' => ['type' => 'integer', 'primary' => true, 'autoincrement' => true],
      'templateId' => ['type' => 'integer', 'required' => true, 'column' => 'template_id',
        'unique' => 'template_id_language', 'index' => 'template_id'
      ],
      'languageId' => ['type' => 'integer', 'required' => true, 'column' => 'language_id',
        'unique' => 'template_id_language', 'index' => 'language_id'
      ],
      'title' => ['type' => 'string', 'required' => true],
      'text' => ['type' => 'text', 'required' => true]
    ];
  }
}

The associated SQL code:

CREATE TABLE IF NOT EXISTS `rendelo_email_template_contents` (
  `template_id` int(10) unsigned NOT NULL,
  `language_id` int(10) unsigned NOT NULL,
  `id` int(10) unsigned NOT NULL,
  `text` longtext COLLATE utf8_unicode_ci NOT NULL,
  `title` varchar(255) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

When I run a query on the mentioned entity like $mapper->get(1), I'm getting the following result:

object(Rendelo\Entity\EmailTemplate\Content)[136]
  protected '_objectId' => string 'entity_590b1fc2a6d699.02420930000000006ab0e471000055e13815cd78' (length=62)
  protected '_data' => 
    array (size=5)
      'id' => int 4
      'templateId' => string '3' (length=1)
      'languageId' => string '1' (length=1)
      'title' => string '' (length=)
      'text' => string '' (length=)

Is it only me or the templateId and languageId field's should be integers, as well as the id? If I compare a foreign key with a primary key, the === operator would return false, because one's type is string and the other's is integer... I find this difficult to understand...

nebulousGirl commented 7 years ago

They should definitely be integers! We need to look at it, but it could also be related to DBAL since field types are a feature of DBAL.