Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong field type #237

Closed
FlipEverything opened this issue May 4, 2017 · 1 comment
Closed

Wrong field type #237

FlipEverything opened this issue May 4, 2017 · 1 comment

Comments

@FlipEverything
Copy link
Contributor

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants