laravel-doctrine / fluent

Fluent mapping driver for Doctrine2

Home Page:http://www.laraveldoctrine.org/docs/current/fluent

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unknown CarbonDateTime type

CaporalDead opened this issue · comments

Hi,

I'm trying Fluent for a new project and I'm getting some trouble using Fluent. When I try to use the $this->carbonDateTime('createdAt') method I get this error :

DBALException in DBALException.php line 228:
Unknown column type "carbondatetime" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information.

I have as dep laravel-doctrine/extensions, gedmo/doctrine-extensions and beberlei/DoctrineExtensions and I added all references to Carbon class in my doctrine.php config file as mentionned on the documentation. I also tried to override the timestamps macro registering the one given in the documentation in the boot method of a service provider which gave me no more results.

If you have an idea :). Thanks !

My model :

<?php

namespace App\Business\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Gedmo\Timestampable\Traits\Timestampable;

class Utilisateur
{
    use Timestampable;

    /**
     * @var int
     */
    protected $id;

    /**
     * @var string
     */
    protected $nom;

    /**
     * @return int
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getNom()
    {
        return $this->nom;
    }

    /**
     * @param string $nom
     *
     * @return Utilisateur
     */
    public function setNom($nom)
    {
        $this->nom = $nom;

        return $this;
    }
}

and this is my mapping file :

<?php

namespace App\Business\Mapping;

use App\Business\Entity\Utilisateur;
use App\Business\Repository\UtilisateurRepository;
use LaravelDoctrine\Fluent\EntityMapping;
use LaravelDoctrine\Fluent\Fluent;

class UtilisateurMapping extends EntityMapping
{
    /**
     * Returns the fully qualified name of the class that this mapper maps.
     *
     * @return string
     */
    public function mapFor()
    {
        return Utilisateur::class;
    }

    /**
     * Load the object's metadata through the Metadata Builder object.
     *
     * @param Fluent $builder
     */
    public function map(Fluent $builder)
    {
        $builder->table('utilisateurs');

        $builder->increments('id');
        $builder->string('nom');
        $builder->carbonDateTime('createdAt');
        $builder->carbonDateTime('updatedAt');

        $builder->entity()->setRepositoryClass(UtilisateurRepository::class);
    }
}

Hey Thomas,

Can you show us that part in the config?

Op donderdag 14 juli 2016 heeft Thomas Sieffert notifications@github.com
het volgende geschreven:

Hi,

I'm trying Fluent for a new project and I'm getting some trouble using
Fluent. When I try to use the $this->carbonDateTime('createdAt') method I
get this error :

DBALException in DBALException.php line 228:
Unknown column type "carbondatetime" requested. Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database introspection then you might have forgot to register all database types for a Doctrine Type. Use AbstractPlatform#registerDoctrineTypeMapping() or have your custom types implement Type#getMappedDatabaseTypes(). If the type name is empty you might have a problem with the cache or forgot some mapping information.

I have as dep laravel-doctrine/extensions, gedmo/doctrine-extensions and
beberlei/DoctrineExtensions and I added all references to Carbon class in
my doctrine.php config file as mentionned on the documentation. I also
tried to override the timestamps macro registering the one given in the
documentation in the boot method of a service provider which gave me no
more results.

If you have an idea :). Thanks !

My model :

id; } /_\* \* @return string _/ public function getNom() { return $this->nom; } /_\* \* @param string $nom \* \* @return Utilisateur */ public function setNom($nom) { $this->nom = $nom; return $this; }} and this is my mapping file : table('utilisateurs'); $builder->increments('id'); $builder->string('nom'); $builder->carbonDateTime('createdAt'); $builder->carbonDateTime('updatedAt'); $builder->entity()->setRepositoryClass(UtilisateurRepository::class); }} — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com//issues/39, or mute the thread https://github.com/notifications/unsubscribe/AHXr4TpMKDYB8J05v1Kqnw_t3DIPICsGks5qVqhcgaJpZM4JM3OY .

Patrick Brouwers__www.patrickbrouwersfilm.com
http://www.patrickbrouwersfilm.com

Yep, here it is :

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Entity Mangers
    |--------------------------------------------------------------------------
    |
    | Configure your Entity Managers here. You can set a different connection
    | and driver per manager and configure events and filters. Change the
    | paths setting to the appropriate path and replace App namespace
    | by your own namespace.
    |
    | Available meta drivers: fluent|annotations|yaml|xml|config|static_php|php
    |
    | Available connections: mysql|oracle|pgsql|sqlite|sqlsrv
    | (Connections can be configured in the database config)
    |
    | --> Warning: Proxy auto generation should only be enabled in dev!
    |
    */
    'managers'                   => [
        'default' => [
            'dev'           => env('APP_DEBUG'),
            'meta'          => env('DOCTRINE_METADATA', 'fluent'),
            'connection'    => env('DB_CONNECTION', 'mysql'),
            'mappings'      => [
                \App\Business\Mapping\UtilisateurMapping::class,
            ],
            'namespaces'    => [
                'App\Business\Entity',
            ],
            'paths'         => [
                base_path('app/Business/Mapping'),
            ],
            'repository'    => Doctrine\ORM\EntityRepository::class,
            'proxies'       => [
                'namespace'     => false,
                'path'          => storage_path('proxies'),
                'auto_generate' => env('DOCTRINE_PROXY_AUTOGENERATE', false)
            ],
            /*
            |--------------------------------------------------------------------------
            | Doctrine events
            |--------------------------------------------------------------------------
            |
            | The listener array expects the key to be a Doctrine event
            | e.g. Doctrine\ORM\Events::onFlush
            |
            */
            'events'        => [
                'listeners'   => [],
                'subscribers' => []
            ],
            'filters'       => [],
            /*
            |--------------------------------------------------------------------------
            | Doctrine mapping types
            |--------------------------------------------------------------------------
            |
            | Link a Database Type to a Local Doctrine Type
            |
            | Using 'enum' => 'string' is the same of:
            | $doctrineManager->extendAll(function (\Doctrine\ORM\Configuration $configuration,
            |         \Doctrine\DBAL\Connection $connection,
            |         \Doctrine\Common\EventManager $eventManager) {
            |     $connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string');
            | });
            |
            | References:
            | http://doctrine-orm.readthedocs.org/en/latest/cookbook/custom-mapping-types.html
            | http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#custom-mapping-types
            | http://doctrine-orm.readthedocs.org/en/latest/cookbook/advanced-field-value-conversion-using-custom-mapping-types.html
            | http://doctrine-orm.readthedocs.org/en/latest/reference/basic-mapping.html#reference-mapping-types
            | http://symfony.com/doc/current/cookbook/doctrine/dbal.html#registering-custom-mapping-types-in-the-schematool
            |--------------------------------------------------------------------------
            */
            'mapping_types' => [
                //'enum' => 'string'
            ]
        ]
    ],
    /*
    |--------------------------------------------------------------------------
    | Doctrine Extensions
    |--------------------------------------------------------------------------
    |
    | Enable/disable Doctrine Extensions by adding or removing them from the list
    |
    | If you want to require custom extensions you will have to require
    | laravel-doctrine/extensions in your composer.json
    |
    */
    'extensions'                 => [
        //LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class,
        LaravelDoctrine\Extensions\Timestamps\TimestampableExtension::class,
        //LaravelDoctrine\Extensions\SoftDeletes\SoftDeleteableExtension::class,
        //LaravelDoctrine\Extensions\Sluggable\SluggableExtension::class,
        //LaravelDoctrine\Extensions\Sortable\SortableExtension::class,
        //LaravelDoctrine\Extensions\Tree\TreeExtension::class,
        //LaravelDoctrine\Extensions\Loggable\LoggableExtension::class,
        //LaravelDoctrine\Extensions\Blameable\BlameableExtension::class,
        //LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension::class,
        //LaravelDoctrine\Extensions\Translatable\TranslatableExtension::class
    ],
    /*
    |--------------------------------------------------------------------------
    | Doctrine custom types
    |--------------------------------------------------------------------------
    |
    | Create a custom or override a Doctrine Type
    |--------------------------------------------------------------------------
    */
    'custom_types'               => [
        'json'             => LaravelDoctrine\ORM\Types\Json::class,
        'CarbonDate'       => DoctrineExtensions\Types\CarbonDateType::class,
        'CarbonDateTime'   => DoctrineExtensions\Types\CarbonDateTimeType::class,
        'CarbonDateTimeTz' => DoctrineExtensions\Types\CarbonDateTimeTzType::class,
        'CarbonTime'       => DoctrineExtensions\Types\CarbonTimeType::class,
    ],
    /*
    |--------------------------------------------------------------------------
    | DQL custom datetime functions
    |--------------------------------------------------------------------------
    */
    'custom_datetime_functions'  => [],
    /*
    |--------------------------------------------------------------------------
    | DQL custom numeric functions
    |--------------------------------------------------------------------------
    */
    'custom_numeric_functions'   => [],
    /*
    |--------------------------------------------------------------------------
    | DQL custom string functions
    |--------------------------------------------------------------------------
    */
    'custom_string_functions'    => [],
    /*
    |--------------------------------------------------------------------------
    | Enable query logging with laravel file logging,
    | debugbar, clockwork or an own implementation.
    | Setting it to false, will disable logging
    |
    | Available:
    | - LaravelDoctrine\ORM\Loggers\LaravelDebugbarLogger
    | - LaravelDoctrine\ORM\Loggers\ClockworkLogger
    | - LaravelDoctrine\ORM\Loggers\FileLogger
    |--------------------------------------------------------------------------
    */
    'logger'                     => env('DOCTRINE_LOGGER', false),
    /*
    |--------------------------------------------------------------------------
    | Cache
    |--------------------------------------------------------------------------
    |
    | Configure meta-data, query and result caching here.
    | Optionally you can enable second level caching.
    |
    | Available: apc|array|file|memcached|redis|void
    |
    */
    'cache'                      => [
        'default'      => env('DOCTRINE_CACHE', 'array'),
        'namespace'    => null,
        'second_level' => false,
    ],
    /*
    |--------------------------------------------------------------------------
    | Gedmo extensions
    |--------------------------------------------------------------------------
    |
    | Settings for Gedmo extensions
    | If you want to use this you will have to require
    | laravel-doctrine/extensions in your composer.json
    |
    */
    'gedmo'                      => [
        'all_mappings' => false
    ],
    /*
     |--------------------------------------------------------------------------
     | Validation
     |--------------------------------------------------------------------------
     |
     |  Enables the Doctrine Presence Verifier for Validation
     |
     */
    'doctrine_presence_verifier' => true,
];

They key has to be lowercased, think it's a mistake in the config.

Op donderdag 14 juli 2016 heeft Thomas Sieffert notifications@github.com
het volgende geschreven:

Yep, here it is :

Warning: Proxy auto generation should only be enabled in dev! | */ 'managers' => [ 'default' => [ 'dev' => env('APP_DEBUG'), 'meta' => env('DOCTRINE_METADATA', 'fluent'), 'connection' => env('DB_CONNECTION', 'mysql'), 'mappings' => [ \App\Business\Mapping\UtilisateurMapping::class, ], 'namespaces' => [ 'App\Business\Entity', ], 'paths' => [ base_path('app/Business/Mapping'), ], 'repository' => Doctrine\ORM\EntityRepository::class, 'proxies' => [ 'namespace' => false, 'path' => storage_path('proxies'), 'auto_generate' => env('DOCTRINE_PROXY_AUTOGENERATE', false) ], /* |-------------------------------------------------------------------------- | Doctrine events |-------------------------------------------------------------------------- | | The listener array expects the key to be a Doctrine event | e.g. Doctrine\ORM\Events::onFlush | */ 'events' => [ 'listeners' => [], 'subscribers' => [] ], 'filters' => [], /* |-------------------------------------------------------------------------- | Doctrine mapping types |-------------------------------------------------------------------------- | | Link a Database Type to a Local Doctrine Type | | Using 'enum' => 'string' is the same of: | $doctrineManager->extendAll(function (\Doctrine\ORM\Configuration $configuration, | \Doctrine\DBAL\Connection $connection, | \Doctrine\Common\EventManager $eventManager) { | $connection->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); | }); | | References: | http://doctrine-orm.readthedocs.org/en/latest/cookbook/custom-mapping-types.html | http://doctrine-dbal.readthedocs.org/en/latest/reference/types.html#custom-mapping-types | http://doctrine-orm.readthedocs.org/en/latest/cookbook/advanced-field-value-conversion-using-custom-mapping-types.html | http://doctrine-orm.readthedocs.org/en/latest/reference/basic-mapping.html#reference-mapping-types | http://symfony.com/doc/current/cookbook/doctrine/dbal.html#registering-custom-mapping-types-in-the-schematool |-------------------------------------------------------------------------- */ 'mapping_types' => [ //'enum' => 'string' ] ] ], /* |-------------------------------------------------------------------------- | Doctrine Extensions |-------------------------------------------------------------------------- | | Enable/disable Doctrine Extensions by adding or removing them from the list | | If you want to require custom extensions you will have to require | laravel-doctrine/extensions in your composer.json | */ 'extensions' => [ //LaravelDoctrine\ORM\Extensions\TablePrefix\TablePrefixExtension::class, LaravelDoctrine\Extensions\Timestamps\TimestampableExtension::class, //LaravelDoctrine\Extensions\SoftDeletes\SoftDeleteableExtension::class, //LaravelDoctrine\Extensions\Sluggable\SluggableExtension::class, //LaravelDoctrine\Extensions\Sortable\SortableExtension::class, //LaravelDoctrine\Extensions\Tree\TreeExtension::class, //LaravelDoctrine\Extensions\Loggable\LoggableExtension::class, //LaravelDoctrine\Extensions\Blameable\BlameableExtension::class, //LaravelDoctrine\Extensions\IpTraceable\IpTraceableExtension::class, //LaravelDoctrine\Extensions\Translatable\TranslatableExtension::class ], /* |-------------------------------------------------------------------------- | Doctrine custom types |-------------------------------------------------------------------------- | | Create a custom or override a Doctrine Type |-------------------------------------------------------------------------- */ 'custom_types' => [ 'json' => LaravelDoctrine\ORM\Types\Json::class, 'CarbonDate' => DoctrineExtensions\Types\CarbonDateType::class, 'CarbonDateTime' => DoctrineExtensions\Types\CarbonDateTimeType::class, 'CarbonDateTimeTz' => DoctrineExtensions\Types\CarbonDateTimeTzType::class, 'CarbonTime' => DoctrineExtensions\Types\CarbonTimeType::class, ], /* |-------------------------------------------------------------------------- | DQL custom datetime functions |-------------------------------------------------------------------------- */ 'custom_datetime_functions' => [], /* |-------------------------------------------------------------------------- | DQL custom numeric functions |-------------------------------------------------------------------------- */ 'custom_numeric_functions' => [], /* |-------------------------------------------------------------------------- | DQL custom string functions |-------------------------------------------------------------------------- */ 'custom_string_functions' => [], /* |-------------------------------------------------------------------------- | Enable query logging with laravel file logging, | debugbar, clockwork or an own implementation. | Setting it to false, will disable logging | | Available: | - LaravelDoctrine\ORM\Loggers\LaravelDebugbarLogger | - LaravelDoctrine\ORM\Loggers\ClockworkLogger | - LaravelDoctrine\ORM\Loggers\FileLogger |-------------------------------------------------------------------------- */ 'logger' => env('DOCTRINE_LOGGER', false), /* |-------------------------------------------------------------------------- | Cache |-------------------------------------------------------------------------- | | Configure meta-data, query and result caching here. | Optionally you can enable second level caching. | | Available: apc|array|file|memcached|redis|void | */ 'cache' => [ 'default' => env('DOCTRINE_CACHE', 'array'), 'namespace' => null, 'second_level' => false, ], /* |-------------------------------------------------------------------------- | Gedmo extensions |-------------------------------------------------------------------------- | | Settings for Gedmo extensions | If you want to use this you will have to require | laravel-doctrine/extensions in your composer.json | */ 'gedmo' => [ 'all_mappings' => false ], /* |-------------------------------------------------------------------------- | Validation |-------------------------------------------------------------------------- | | Enables the Doctrine Presence Verifier for Validation | */ 'doctrine_presence_verifier' => true, ``` ]; — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com//issues/39#issuecomment-232797107, or mute the thread https://github.com/notifications/unsubscribe/AHXr4V8FUfmN7p8Ckc97Cs9QDOiC4s9bks5qVqkvgaJpZM4JM3OY .

Patrick Brouwers__www.patrickbrouwersfilm.com
http://www.patrickbrouwersfilm.com

Yep, that was it, it's a typo in the documentation, I'll do a PR to fix that :). Thanks !