Coder Social home page Coder Social logo

fluent's People

Contributors

adrorocker avatar dpgover avatar dpslwk avatar eigan avatar gordinskiy avatar guiwoda avatar hiddeco avatar patrickbrouwers avatar vv12131415 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fluent's Issues

Error when changing to fluent

As soon as I change my metadata at doctrine config to fluent i get this error when run php artisan doctrine:migrations:diff :

[Doctrine\Common\Annotations\AnnotationException] [Semantical Error] The annotation "@Doctrine\ORM\Mapping\MappedSuperclass" in class Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTransla tion does not exist, or could not be auto-loaded.

findOneBy() and findBy() not working with embedded fields

This is part of my UserMapping

public function map(Fluent $builder)
    {
        $builder->increments('id');
        $builder->embed(FirstName::class)->noPrefix();
        $builder->embed(LastName::class)->noPrefix();
        $builder->embed(Email::class)->noPrefix();
    }

When I try to:

        $users = $this->userRepository->findOneBy([
            'email' => '[email protected]'
        ]);

I get this:
Doctrine \ ORM \ ORMException Unrecognized field: email

But if I change the UserMapping to use a string instead of the embedded field

public function map(Fluent $builder)
    {
        $builder->increments('id');
        $builder->embed(FirstName::class)->noPrefix();
        $builder->embed(LastName::class)->noPrefix();
        $builder->string('email');
    }

This will work as expected.

Any thoughts of why i get Unrecognized field: email when the field is a ValueObject?

Thank you!

[Help] How to mapping many-to-many relationships and accessing intermediate table

Hey guys.

I would really appreciate the community's help, because I'm following the fluent documentation step by step, but I'm not succeeding.

I'm migrating a project from eloquent to doctrine, where the tables are outside the class mapping convention.

I've reached an impasse in the many-to-many relationship where I need access to intermediate table columns.

I ran the command php artisan doctrine:migrations:diff to check the mapping with the current database state and I only had a few changes in the name of the foreign keys.

But when trying to access the relationship, I don't have access to the objects of the intermediate class, an empty collection is returned to me.

Calls and responses

When calling the estimate repository and the entry types property that represents the intermediate table, I get this return.

$estimate_repository = EntityManager::getRepository(Estimate::class);
$estimate = $estimate_repository->findOneBy(['id'=>1]);
dd($estimate);

image

ER Diagram:

image

Entities:

Estimate


namespace App\Domain\Estimate;

use DateTime;

use App\Domain\Entry\EntryType;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

class Estimate
{
    public $id;
    private $created_at;
    private $updated_at;

    public Collection $entry_types;

    public function __construct(
        public DateTime $period,
        public float $start_balance,
        public ?string $description = null,
        public bool $active,
    )
    {
        $this->entry_types = new ArrayCollection();
    }
}

EntryType


namespace App\Domain\Entry;

use Doctrine\Common\Collections\ArrayCollection;

class EntryType
{
    public $id;
    private $created_at;
    private $updated_at;

    public $estimates;

    public function __construct(
        public string $description,
        public string $type,
        public string $status,
    ){
        $this->estimates = new ArrayCollection();
    }
}

EstimateEntryType (intermediate)


namespace App\Domain\Estimate;

use App\Domain\Entry\EntryType;

class EstimateEntryType
{
    private $created_at;
    private $updated_at;

    public function __construct(
        public Estimate $estimate,
        public EntryType $entry_type,
        public float $value,
        public string $comment,
    )
    {
        //
    }
}

Mappers

Estimate

namespace App\Infrastructure\LaravelDoctrine\Mappings\Estimate;

use LaravelDoctrine\Fluent\Fluent;
use LaravelDoctrine\Fluent\EntityMapping;
use LaravelDoctrine\Fluent\Builders\Field;

use App\Domain\Estimate\Estimate;
use App\Domain\Entry\EntryType;
use App\Domain\Estimate\EstimateEntryType;

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

    /**
     * Load the object's metadata through the Metadata Builder object.
     *
     * @param Fluent $builder
     */
    public function map(Fluent $builder)
    {
        $builder->table('orcamentos');
        $builder->increments('id')->unsigned();
        $builder->string('description', function(Field $field){
            $field->name('descricao')->length(150)->nullable();
        });
        $builder->date('period', function(Field $field){
            $field->name('data');
        });
        $builder->unique(['data']);
        $builder->float('start_balance', function(Field $field){
            $field->name('saldo_inicial_quanto_sobra')->default(0)->nullable();
        });
        $builder->boolean('active', function(Field $field){
            $field->name('ativo')->default(0);
        });
        $builder->dateTime('created_at')->nullable()->timestampable()->onCreate();
        $builder->dateTime('updated_at')->nullable()->timestampable()->onUpdate();
        $builder->oneToMany(EstimateEntryType::class, 'entry_types')
                ->mappedBy('estimate')
                ->fetch('EAGER');
    }
} 

EntryType

namespace App\Infrastructure\LaravelDoctrine\Mappings\Entry;

use LaravelDoctrine\Fluent\Fluent;
use LaravelDoctrine\Fluent\EntityMapping;
use LaravelDoctrine\Fluent\Builders\Field;

use App\Domain\Entry\EntryType;
use App\Domain\Estimate\Estimate;
use App\Domain\Estimate\EstimateEntryType;

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

    /**
     * Load the object's metadata through the Metadata Builder object.
     *
     * @param Fluent $builder
     */
    public function map(Fluent $builder)
    {
        $builder->table('tipolancamentos');
        $builder->increments('id')->unsigned();
        $builder->string('description', function(Field $field){
            $field->name('descricao')->length(150);
        });
        $builder->string('type', function(Field $field){
            $field->name('tipo')->length(1)->nullable();
        });
        $builder->string('status')->length(1);
        $builder->dateTime('created_at')->nullable()->timestampable()->onCreate();
        $builder->dateTime('updated_at')->nullable()->timestampable()->onUpdate();

        $builder->oneToMany(EstimateEntryType::class, 'estimates')
                ->mappedBy('entry_types');
    }
} 

EstimateEntryType (intermediate table)

namespace App\Infrastructure\LaravelDoctrine\Mappings\Estimate;

use LaravelDoctrine\Fluent\Fluent;
use LaravelDoctrine\Fluent\EntityMapping;
use LaravelDoctrine\Fluent\Builders\Field;

use App\Domain\Estimate\Estimate;
use App\Domain\Entry\EntryType;
use App\Domain\Estimate\EstimateEntryType;

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

    /**
     * Load the object's metadata through the Metadata Builder object.
     *
     * @param Fluent $builder
     */
    public function map(Fluent $builder)
    {
        $builder->table('orcamentotipolancamentos');
        $builder->string('value', function(Field $field){
            $field->name('valor')->length(50)->nullable();
        });
        $builder->text('comment', function(Field $field){
            $field->name('comentario')->nullable();
        });
        $builder->dateTime('created_at')->nullable()->timestampable()->onCreate();
        $builder->dateTime('updated_at')->nullable()->timestampable()->onUpdate();
        $builder->manyToOne(EntryType::class,'entry_type')
                     ->foreignKey('tipolancamento_id')
                     ->fetch('EAGER');
        $builder->manyToOne(Estimate::class,'estimate')
                ->foreignKey('orcamento_id')
                ->fetch('EAGER');
        $builder->primary(['entry_type','estimate']);
    }
}

Generated diff migration


declare(strict_types=1);

namespace Database\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20230301190808 extends AbstractMigration
{
    public function getDescription(): string
    {
        return 'Rename orcamentotipolancamentos indexes';
    }

    public function up(Schema $schema): void
    {
        $this->addSql('ALTER TABLE orcamentotipolancamentos ADD CONSTRAINT FK_ED4B2808E421AB39 FOREIGN KEY (tipolancamento_id) REFERENCES tipolancamentos (id)');
        $this->addSql('ALTER TABLE orcamentotipolancamentos ADD CONSTRAINT FK_ED4B2808A01CF1CA FOREIGN KEY (orcamento_id) REFERENCES orcamentos (id)');
        $this->addSql('ALTER TABLE orcamentotipolancamentos RENAME INDEX orcamentotipolancamentos_orcamento_id_foreign TO IDX_ED4B2808A01CF1CA');
    }

    public function down(Schema $schema): void
    {
        $this->addSql('ALTER TABLE orcamentotipolancamentos DROP FOREIGN KEY FK_ED4B2808E421AB39');
        $this->addSql('ALTER TABLE orcamentotipolancamentos DROP FOREIGN KEY FK_ED4B2808A01CF1CA');
        $this->addSql('ALTER TABLE orcamentotipolancamentos RENAME INDEX idx_ed4b2808a01cf1ca TO orcamentotipolancamentos_orcamento_id_foreign');
    }
}

Error running doctrine:generate:entities command when using timestampable

I'm getting the following error when trying to run this command for an entity using timestampable:

[ErrorException]
Argument 1 passed to LaravelDoctrine\Fluent\Extensions\Gedmo\AbstractTrackingExtension::__construct() must be an instance of LaravelDoctrine\Fluent\Extensions\ExtensibleClass
Metadata, instance of Doctrine\ORM\Mapping\ClassMetadata given, called in /home/vagrant/code/application/vendor/laravel-doctrine/fluent/src/Extensions/Gedmo/Timestampable.php
on line 22

Mapping defined as follows:

public function mapFor()
{
    return Article::class;
}

public function map(Fluent $builder)
{
    $builder->increments('id');
    $builder->string('title');
    $builder->timestamps();
}

Defer adding gedmo mappings to when the extension is enabled

Gedmo provides some abstract classes and default implementations for some of their extensions, and we've added mappings for them in the same way they do for annotations.

When mappings for all implementations are added to the FluentDriver, Fluent ends up creating tables for extensions that may not be needed yet. It would be nice to have those mappings added only if that specific extension is enabled.

Access custom types in Mappings

Hello,

I am trying to use uuid as primary keys in my database so i tried adding some custom types

Here is part of my doctrine config file:

  'mapping_types' => [
         'binary' => 'uuid_binary'
  ],
 
  ....
 
 'custom_types'               => [
     'json' => LaravelDoctrine\ORM\Types\Json::class,
     'uuid' => Ramsey\Uuid\Doctrine\UuidType::class,
     'uuid_binary' => Ramsey\Uuid\Doctrine\UuidBinaryType::class,
 ],

In the Mapping I can't seem to be able to use either:

$builder->uuid('id')->primary();
$builder->uuid_binary('id')->primary();

this will result in

[InvalidArgumentException]
Fluent builder method [uuid] does not exist

[InvalidArgumentException]
Fluent builder method [uuid_binary] does not exist

Is it something i missed?

Thanks for your help!

Does this package depend on laravel framework or its components?

Hello there, I am amazed to find this library as I've always been looking for a fluent API similar to C#'s entity framework fluent API. To me this is by far the most optimal solution for data mapping, as I do not like either annotations(violating separation of concerns) or XML(the notorious XML hell). Thank you so much for making this library, its an eye opener and can work in production environment.

I wonder though, is there a reason why the top namespace is LaravelDoctrine? I looked at the composer.json and did not find any dependency on Laravel framework and its core libraries. Does this mean that, the library can be used with or without Laravel framework? I thought the package LaravelDoctrine is supposed to be used for Laravel's implementation of Doctrine only, correct me if I am wrong.

Support for Laravel 10 - doctrine/persistence upgrade to ^3?

I'm currently investigating whether laravel-doctrine is the solution I've been hoping for for my project, and the fluent package looks like exactly the sort of workflow I was hoping to use! The Laravel system I am trying to use laravel-doctrine/fluent with is using illuminate ^10, though; this requires laravel-doctrine/orm ^2, which in turn requires doctrine/persistence ^3, which clashes the requirement in this package.

I was just wondering whether there were any plans to update this package to support doctrine/persistence ^3, or if anyone had an idea of how much work would be involved in doing that upgrade? I had a go myself, but quickly realised that because I have no idea how either package works, and having not used it before, I don't know whether there are actually any issues, or how to solve any I do find!

hasOne / belongsTo mapping fails schema validation

Hello ๐Ÿ‘‹

I can't seem to get the hasOne and belongsTo mapping to pass schema validation. If I run php artisan doctrine:schema:validate --skip-sync it gives me an error like this:

* If association App\Domain\User\Settings#user is many-to-one, then the inversed side App\Domain\User#settings has to be one-to-many

It seems like the problem is that hasOne returns a OneToOne and belongsTo returns a ManyToOne? Should hasOne return a OneToMany instead?

I've worked around it in the interim by using oneToOne instead.

I added a test case that illustrates the issue here: https://github.com/yuloh/fluent/tree/hasOne-mapping-issue

Specifically the error I am getting is similar to this one:

If association Tests\Stubs\Entities\StubEntity#parent is many-to-one, then the inversed side Tests\Stubs\Entities\StubEntity#parent has to be one-to-many.

JSONB option being ignored

Using annotation, I'm able to add the jsonb: true option and it builds as expected, but when I use fluent, it just creates a standard json postgres column:

$builder->jsonArray('metadata')->option('jsonb', true);

any idea why that wouldn't work?

$builder->string('name')->index(); returns an error

I set up a simple mapping and when I added an index using the example below I get...

[BadMethodCallException]                     
FieldBuilder method [index] does not exist.

Example

public function map(Fluent $builder)
{
    $builder->increments('id');
    $builder->string('name');
    $builder->string('type')->index();
    $builder->timestamps();
}

However, this works

public function map(Fluent $builder)
{
    $builder->increments('id');
    $builder->string('name');
    $builder->string('type');
    $builder->timestamps();

    $builder->index('type');
}

Composer Dependency Issues on Installation

It appears if you install laravel-doctrine/orm:1.5.* first and then attempt into install this package a dependency resolution error occurs and this package can't be installed, however installing this package first and then laravel-doctrine/orm:1.5.*, everything resolves fine.

Composer Output

โžœ  code git:(master) โœ— composer require laravel-doctrine/fluent
    1/1:        http://repo.packagist.org/p/provider-latest$1c8814916c47f54cf898c2e891cd2d4d499b0973ac49140a7b6eb341acc192f8.json
    Finished: success: 1, skipped: 0, failure: 0, total: 1
Using version ^1.1 for laravel-doctrine/fluent
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Conclusion: don't install laravel-doctrine/fluent 1.1.6
    - Conclusion: don't install laravel-doctrine/fluent 1.1.5
    - Conclusion: don't install laravel-doctrine/fluent 1.1.4
    - Conclusion: don't install laravel-doctrine/fluent 1.1.3
    - Conclusion: don't install laravel-doctrine/fluent 1.1.2
    - Conclusion: don't install laravel-doctrine/fluent 1.1.1
    - Conclusion: don't install laravel-doctrine/fluent 1.1.0
    - Conclusion: remove doctrine/common 2.12.0
    - Conclusion: don't install doctrine/common 2.12.0
    - doctrine/orm 2.5.x-dev requires doctrine/common >=2.5-dev,<2.9-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, 2.7.x-dev, 2.8.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3, v2.8.0, v2.8.1].
    - doctrine/orm v2.5.0 requires doctrine/common >=2.5-dev,<2.6-dev -> satisfiable by doctrine/common[2.5.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3].
    - doctrine/orm v2.5.0-RC1 requires doctrine/common >=2.5-dev,<2.6-dev -> satisfiable by doctrine/common[2.5.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3].
    - doctrine/orm v2.5.0-RC2 requires doctrine/common >=2.5-dev,<2.6-dev -> satisfiable by doctrine/common[2.5.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3].
    - doctrine/orm v2.5.0-alpha1 requires doctrine/common >=2.5-dev,<2.6-dev -> satisfiable by doctrine/common[2.5.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3].
    - doctrine/orm v2.5.0-alpha2 requires doctrine/common >=2.5-dev,<2.6-dev -> satisfiable by doctrine/common[2.5.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3].
    - doctrine/orm v2.5.0-beta1 requires doctrine/common >=2.5-dev,<2.6-dev -> satisfiable by doctrine/common[2.5.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3].
    - doctrine/orm v2.5.1 requires doctrine/common >=2.5-dev,<2.6-dev -> satisfiable by doctrine/common[2.5.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3].
    - doctrine/orm v2.5.10 requires doctrine/common >=2.5-dev,<2.9-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, 2.7.x-dev, 2.8.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3, v2.8.0, v2.8.1].
    - doctrine/orm v2.5.11 requires doctrine/common >=2.5-dev,<2.9-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, 2.7.x-dev, 2.8.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3, v2.8.0, v2.8.1].
    - doctrine/orm v2.5.12 requires doctrine/common >=2.5-dev,<2.9-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, 2.7.x-dev, 2.8.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3, v2.8.0, v2.8.1].
    - doctrine/orm v2.5.13 requires doctrine/common >=2.5-dev,<2.9-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, 2.7.x-dev, 2.8.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3, v2.8.0, v2.8.1].
    - doctrine/orm v2.5.14 requires doctrine/common >=2.5-dev,<2.9-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, 2.7.x-dev, 2.8.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3, v2.8.0, v2.8.1].
    - doctrine/orm v2.5.2 requires doctrine/common >=2.5-dev,<2.6-dev -> satisfiable by doctrine/common[2.5.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3].
    - doctrine/orm v2.5.3 requires doctrine/common >=2.5-dev,<2.7-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2].
    - doctrine/orm v2.5.4 requires doctrine/common >=2.5-dev,<2.7-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2].
    - doctrine/orm v2.5.5 requires doctrine/common >=2.5-dev,<2.7-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2].
    - doctrine/orm v2.5.6 requires doctrine/common >=2.5-dev,<2.8-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, 2.7.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3].    - doctrine/orm v2.5.7 requires doctrine/common >=2.5-dev,<2.9-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, 2.7.x-dev, 2.8.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3, v2.8.0, v2.8.1].
    - doctrine/orm v2.5.8 requires doctrine/common >=2.5-dev,<2.9-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, 2.7.x-dev, 2.8.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3, v2.8.0, v2.8.1].
    - doctrine/orm v2.5.9 requires doctrine/common >=2.5-dev,<2.9-dev -> satisfiable by doctrine/common[2.5.x-dev, 2.6.x-dev, 2.7.x-dev, 2.8.x-dev, v2.5.0, v2.5.0-beta1, v2.5.1, v2.5.2, v2.5.3, v2.6.0, v2.6.1, v2.6.2, v2.7.0, v2.7.1, v2.7.2, v2.7.3, v2.8.0, v2.8.1].
    - Can only install one of: doctrine/common[2.5.x-dev, 2.12.0].
    - Can only install one of: doctrine/common[2.6.x-dev, 2.12.0].
    - Can only install one of: doctrine/common[2.7.x-dev, 2.12.0].
    - Can only install one of: doctrine/common[2.8.x-dev, 2.12.0].
    - Can only install one of: doctrine/common[v2.5.0, 2.12.0].
    - Can only install one of: doctrine/common[v2.5.0-beta1, 2.12.0].
    - Can only install one of: doctrine/common[v2.5.1, 2.12.0].
    - Can only install one of: doctrine/common[v2.5.2, 2.12.0].
    - Can only install one of: doctrine/common[v2.5.3, 2.12.0].
    - Can only install one of: doctrine/common[v2.6.0, 2.12.0].
    - Can only install one of: doctrine/common[v2.6.1, 2.12.0].
    - Can only install one of: doctrine/common[v2.6.2, 2.12.0].
    - Can only install one of: doctrine/common[v2.7.0, 2.12.0].
    - Can only install one of: doctrine/common[v2.7.1, 2.12.0].
    - Can only install one of: doctrine/common[v2.7.2, 2.12.0].
    - Can only install one of: doctrine/common[v2.7.3, 2.12.0].
    - Can only install one of: doctrine/common[v2.8.0, 2.12.0].
    - Can only install one of: doctrine/common[v2.8.1, 2.12.0].
    - Conclusion: don't install doctrine/orm v2.7.0|install doctrine/orm 2.5.x-dev|install doctrine/orm v2.5.0|install doctrine/orm v2.5.0-RC1|install doctrine/orm v2.5.0-RC2|install doctrine/orm v2.5.0-alpha1|install doctrine/orm v2.5.0-alpha2|install doctrine/orm v2.5.0-beta1|install doctrine/orm v2.5.1|install doctrine/orm v2.5.10|install doctrine/orm v2.5.11|install doctrine/orm v2.5.12|install doctrine/orm v2.5.13|install doctrine/orm v2.5.14|install doctrine/orm v2.5.2|install doctrine/orm v2.5.3|install doctrine/orm v2.5.4|install doctrine/orm v2.5.5|install doctrine/orm v2.5.6|install doctrine/orm v2.5.7|install doctrine/orm v2.5.8|install doctrine/orm v2.5.9
    - Conclusion: don't install laravel-doctrine/fluent 1.1.6|remove doctrine/orm v2.7.0|install doctrine/orm 2.5.x-dev|install doctrine/orm v2.5.0|install doctrine/orm v2.5.0-RC1|install doctrine/orm v2.5.0-RC2|install doctrine/orm v2.5.0-alpha1|install doctrine/orm v2.5.0-alpha2|install doctrine/orm v2.5.0-beta1|install doctrine/orm v2.5.1|install doctrine/orm v2.5.10|install doctrine/orm v2.5.11|install doctrine/orm v2.5.12|install doctrine/orm v2.5.13|install doctrine/orm v2.5.14|install doctrine/orm v2.5.2|install doctrine/orm v2.5.3|install doctrine/orm v2.5.4|install doctrine/orm v2.5.5|install doctrine/orm v2.5.6|install doctrine/orm v2.5.7|install doctrine/orm v2.5.8|install doctrine/orm v2.5.9     
    - Conclusion: don't install laravel-doctrine/fluent 1.1.6|don't install doctrine/orm v2.7.0|install doctrine/orm 2.5.x-dev|install doctrine/orm v2.5.0|install doctrine/orm v2.5.0-RC1|install doctrine/orm v2.5.0-RC2|install doctrine/orm v2.5.0-alpha1|install doctrine/orm v2.5.0-alpha2|install doctrine/orm v2.5.0-beta1|install doctrine/orm v2.5.1|install doctrine/orm v2.5.10|install doctrine/orm v2.5.11|install doctrine/orm v2.5.12|install doctrine/orm v2.5.13|install doctrine/orm v2.5.14|install doctrine/orm v2.5.2|install doctrine/orm v2.5.3|install doctrine/orm v2.5.4|install doctrine/orm v2.5.5|install doctrine/orm v2.5.6|install doctrine/orm v2.5.7|install doctrine/orm v2.5.8|install doctrine/orm v2.5.9
    - Conclusion: don't install laravel-doctrine/fluent 1.1.6|remove doctrine/orm v2.7.0|install doctrine/orm 2.5.x-dev|install doctrine/orm v2.5.0|install doctrine/orm v2.5.0-RC1|install doctrine/orm v2.5.0-RC2|install doctrine/orm v2.5.0-alpha1|install doctrine/orm v2.5.0-alpha2|install doctrine/orm v2.5.0-beta1|install doctrine/orm v2.5.1|install doctrine/orm v2.5.10|install doctrine/orm v2.5.11|install doctrine/orm v2.5.12|install doctrine/orm v2.5.13|install doctrine/orm v2.5.14|install doctrine/orm v2.5.2|install doctrine/orm v2.5.3|install doctrine/orm v2.5.4|install doctrine/orm v2.5.5|install doctrine/orm v2.5.6|install doctrine/orm v2.5.7|install doctrine/orm v2.5.8|install doctrine/orm v2.5.9     
    - Conclusion: don't install laravel-doctrine/fluent 1.1.6|don't install doctrine/orm v2.7.0|install doctrine/orm 2.5.x-dev|install doctrine/orm v2.5.0|install doctrine/orm v2.5.0-RC1|install doctrine/orm v2.5.0-RC2|install doctrine/orm v2.5.0-alpha1|install doctrine/orm v2.5.0-alpha2|install doctrine/orm v2.5.0-beta1|install doctrine/orm v2.5.1|install doctrine/orm v2.5.10|install doctrine/orm v2.5.11|install doctrine/orm v2.5.12|install doctrine/orm v2.5.13|install doctrine/orm v2.5.14|install doctrine/orm v2.5.2|install doctrine/orm v2.5.3|install doctrine/orm v2.5.4|install doctrine/orm v2.5.5|install doctrine/orm v2.5.6|install doctrine/orm v2.5.7|install doctrine/orm v2.5.8|install doctrine/orm v2.5.9
    - Installation request for doctrine/common (locked at 2.12.0) -> satisfiable by doctrine/common[2.12.0].
    - Installation request for laravel-doctrine/fluent ^1.1 -> satisfiable by laravel-doctrine/fluent[1.1.0, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.1.6, 1.1.x-dev].
    - Conclusion: remove doctrine/orm v2.7.0|install doctrine/orm 2.5.x-dev|install doctrine/orm v2.5.0|install doctrine/orm v2.5.0-RC1|install doctrine/orm v2.5.0-RC2|install doctrine/orm v2.5.0-alpha1|install doctrine/orm v2.5.0-alpha2|install doctrine/orm v2.5.0-beta1|install doctrine/orm v2.5.1|install doctrine/orm v2.5.10|install doctrine/orm v2.5.11|install doctrine/orm v2.5.12|install doctrine/orm v2.5.13|install doctrine/orm v2.5.14|install doctrine/orm v2.5.2|install doctrine/orm v2.5.3|install doctrine/orm v2.5.4|install doctrine/orm v2.5.5|install doctrine/orm v2.5.6|install doctrine/orm v2.5.7|install doctrine/orm v2.5.8|install doctrine/orm v2.5.9
    - laravel-doctrine/fluent 1.1.x-dev requires doctrine/orm 2.5.*|2.6.* -> satisfiable by doctrine/orm[2.5.x-dev, 2.6.x-dev, v2.5.0, v2.5.0-RC1, v2.5.0-RC2, v2.5.0-alpha1, v2.5.0-alpha2, v2.5.0-beta1, v2.5.1, v2.5.10, v2.5.11, v2.5.12, v2.5.13, v2.5.14, v2.5.2, v2.5.3, v2.5.4, v2.5.5, v2.5.6, v2.5.7, v2.5.8, v2.5.9, v2.6.0, v2.6.1, v2.6.2, v2.6.3, v2.6.4, v2.6.5, v2.6.6].
    - Can only install one of: doctrine/orm[2.6.x-dev, v2.7.0].
    - Can only install one of: doctrine/orm[v2.6.0, v2.7.0].
    - Can only install one of: doctrine/orm[v2.6.1, v2.7.0].
    - Can only install one of: doctrine/orm[v2.6.2, v2.7.0].
    - Can only install one of: doctrine/orm[v2.6.3, v2.7.0].
    - Can only install one of: doctrine/orm[v2.6.4, v2.7.0].
    - Can only install one of: doctrine/orm[v2.6.5, v2.7.0].
    - Can only install one of: doctrine/orm[v2.6.6, v2.7.0].
    - Installation request for doctrine/orm (locked at v2.7.0) -> satisfiable by doctrine/orm[v2.7.0].


Installation failed, reverting ./composer.json to its original content.

I'm unsure myself but I believe this has more than likely something to do with laravel-doctrine/orm:1.5.* allowing for doctrine/orm:^2.7 to be installed but this package only allowing 2.6.* at most, and composer won't downgrade the doctrine/orm package.

How to escape reserved words with Fluent mappping?

My Notification entity has a field named level. I'm using Oracle Database where level is a reserved keyword so for every SQL than involves notification the level field needs to be escaped to "LEVEL" otherwise Oracle will throw an error

ORA-01747: invalid user.table.column, table.column, or column specification

I know Doctrine does not quote identifiers automatically and quoting column names needs to be done explicitly using ticks in the definition.

The problem is I don't know who to achieve the ticks feature when using LaravelDoctrine\Fluent\Fluent. If I try adding the ticks ...

    public function map(Fluent $builder)
    {
        $builder->increments('id');
        $builder->string('`level`');
        // ... redacted for brevity
    }

... then I always get the error

Property App\Models\Notification::$`level` does not exist

So, how do I specify in FluentMapping that level column should be escaped?

Cannot use enum column type

Hello,

I can't seem to be able to use the enum type.

in my config, i have uncommented this line:

        'mapping_types' => [
            'enum' => 'string'
        ]

And in the mapping I use it like this:
$builder->field('enum', 'someField');

Do I need to do something else to make it work?

Thanks a lot!

Index method not obeying columName() it tries to create the index using the field name instead

When trying to use this kind of construct $builder->integer('userId')->columnName('user_id')->index('user_id_token_index')->nullable(); Fluent is giving me the error that there is no column named userId on the database. Obvious, because I changed the column name and I'm not using the class's field name. So I tried a workaround that I don't know if it's the correct form to implement it, but solved the issue. Bellow the code snippets:

Field.php

/**
 * @param string|null $name
 *
 * @return Field
 */
public function index($name = null)
{
    if (!isset($this->fieldBuilder->getMapping()['columnName'])){
        $columnName = $this->getName();
    } else {
        $columnName = $this->fieldBuilder->getMapping()['columnName'];
    }
    $index = new Index(
    $this->metaDatabuilder,
      [$columnName]//$this->getName()]
    );

    if ($name !== null) {
        $index->name($name);
    }

    $this->callbackAndQueue($index);

    return $this;
}

FieldBuilder.php, added a method to get the mapping information

public function getMapping() {
    return $this->mapping;
}

Another workaround is to do like this on the mapping file:

$builder->integer('userId')->columnName('user_id');
$builder->index('user_id');

FluentDriver use error with Laravel 8

I try to use laravel-doctrine/fluent 1.1.7 with Laravel 8, but in the file FluentDriver.php there have some use error for:

  • Doctrine\Common\Persistence\Mapping\ClassMetadata
  • Doctrine\Common\Persistence\Mapping\Driver\MappingDriver
    I need to remove Common in the use for everything work.

Primary Key by Embeddable Value

Is there a way to have part of an embeddable be the primary key for an entity?

A little background in what I am trying to do. I am writing an app which has the data structure like this

object : {
    id => 1
    aliases => [
        'default' => 'bob',
        'proper' => 'robert'
    ]
}

The way the app will work is it allows an entity to have multiple aliases which fulfill multiple alias types. None of the aliases between the different objects can be the same. One object cannot have two aliases with the same alias type.

I think this is a good instance to have an embeddable alias value object, but I am having trouble adding the constraints. I would like the alias value to be the primary key, and have a unique key which is a composite of all the row data.... expecting the rows to look like this

id | alias_type | alias_value
1 default bob
1 proper robert

Am I going about this wrong?

Add hardDelete option for softDeleteable fields

Looks like hardDelete feature can't be enabled when using Fluent. At least I can't find some obvious or documented way.

The SoftDeleteableListener only considers hardDelete as enabled if it's explicitly specified in config, and the is no such option in SoftDeleteable::build method.

Workaround I'm currently using:

$builder->dateTime('deletedAt')->nullable();
$builder->entity()->getClassMetadata()->addExtension(\Gedmo\SoftDeleteable\Mapping\Driver\Fluent::EXTENSION_NAME, [
    'softDeleteable' => true,
    'fieldName'      => 'deletedAt',
    'hardDelete'     => true,
    'timeAware'      => false,
]);

It would be nice to have a fluent method like timeAware:

$builder->softDelete('deletedAt')->hardDelete();
// or
$builder->softDelete('deletedAt')->hardDelete(true);

Null object relationship with builder

I have an entity that has an optional relationship, and it's represented in my domain as a Null Object. When the relationship exists and is non-null, this works fine:

$builder->hasOne(Tote::class);

However, when the relationship isn't set, it fails because NullTote (the default value) can't map to Tote.

Is there an easier way of working with null objects in Doctrine's mappings that I'm unaware of? Or is this going to get dirty? I can always try to resolve them (http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/resolve-target-entity-listener.html) but that doesn't really solve my problem.

Unknown CarbonDateTime type

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);
    }
}

doctrine/orm version bump

@eigan For this package to work with Laravel 9, doctrine/inflector needs to be used in version 2.0 at least.
Version 1.4 changed the API and the old one is deprecated.

I left a PR for this: #74

Also, this package is requiring multiple doctrine/orm versions, while laravel-doctrine/orm is only requiring ^2.6.
Do you think we can change the requirements on composer.json to be alligned?

autoIncrement on non primary() field throws error

I'm trying to make a non primary key column to be autoIncrement but it's throwing error

PDOException: SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value

BUT when I'm removing the autoIncrement here

$builder->integer('taskNumber')
           ->unsigned()
           //->autoIncrement() // removing this will make it work
           ->treePathSource();

What is also happening is that the path is not getting the value taskNumber hence the path field has always empty when saved to database (maybe because of the autoIncrement not being used? but putting it causes error).

here is my mapping

public function map(Fluent $builder)
    {
        $builder->tree()->asMaterializedPath();
        $builder->entity()->setRepositoryClass(MaterializedPathRepository::class);

        $builder->table('task')
            ->charset('utf8mb4')
            ->collate('utf8mb4_unicode_ci');

        $builder->field('uuid', 'id')->primary();
        $builder->string('name')->length(191);
        $builder->text('description')->nullable();
        $builder->integer('status');
        $builder->carbonDateTime('deadline')->nullable();
        $builder->carbonDateTime('assignedAt')->nullable();
        $builder->manyToOne(Collaborator::class, 'assignee')->nullable();
        $builder->manyToOne(Collaborator::class, 'owner');

        $builder->oneToMany(Task::class, 'subTasks')->mappedBy('parent');
        $builder->manyToOne(Task::class, 'parent')
            ->cascadePersist()
            ->nullable()
            ->inversedBy('subTasks')
            ->treeParent();

        $builder->integer('taskNumber')
            ->unsigned()
            ->autoIncrement()
            ->treePathSource();

        $builder->string('path')
            ->treePath('/')
            ->appendId(false)
            ->startsWithSeparator()
            ->endsWithSeparator(false);

        $builder->integer('level')
            ->unsigned()
            ->treeLevel();

        $builder->timestamps();
    }

Model Factory

$factory->define(Task::class, function(Faker\Generator $faker, $attributes) {
    return [
        'id' => Uuid::uuid4(),
        'name' => $faker->sentences(1, $asText = true),
        'deadline' => Carbon::now()->addDays(1),
        'status' => TaskStatus::PENDING,
        'assignedAt' => Carbon::now(),
        'assignee' => $attributes['assignee'] ?? entity(Collaborator::class)->create(),
        'owner' => $attributes['owner'] ?? entity(Collaborator::class)->create(),
    ];
});

$factory->defineAs(Task::class, 'today', function(Faker\Generator $faker, $attributes) {
    $now = Carbon::now();

    return [
        'id' => Uuid::uuid4(),
        'name' => $faker->sentences(1, $asText = true),
        'assignedAt' => $now,
        'deadline' => $now->addDays(1),
        'status' => TaskStatus::PENDING,
        'assignee' => $attributes['assignee'] ?? entity(Collaborator::class)->create(),
        'owner' => $attributes['owner'] ?? entity(Collaborator::class)->create(),
    ];
});

Fluent builder method [nestedSet] does not exist

Packages:
"laravel-doctrine/orm": "1.2.*",
"laravel-doctrine/extensions": "1.0.*",
"gedmo/doctrine-extensions": "^2.4",
"beberlei/DoctrineExtensions": "^1.0",
"laravel-doctrine/fluent": "^1.1"

'managers' => [
'default' => [
'meta' => 'fluent',
...
1. (fixed) I received "[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@doctrine\ORM\Mapping\MappedSuperclass" in class Gedmo\Translatable\Entity\MappedSuperclass\AbstractPersonalTranslation does not exist, or could not be auto-loaded."
I fixed this error with a custom ServiceProvider:
public function boot()
{
AnnotationRegistry::registerFile(base_path('vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'));
GedmoExtensions::registerAll(new MappingDriverChain());
}
2. "Fluent builder method [nestedSet] does not exist"
public function map(Fluent $builder)
{
$builder->bigIncrements('id');
$builder->string('name')->nullable();
$builder->nestedSet(); //here it fails
}

php artisan doctrine:schema:update

Checking if database connected to default entity manager needs updating...

[InvalidArgumentException]
Fluent builder method [nestedSet] does not exist

The oneToOne relation not exist joinColumn method

public function map(Fluent $builder){
$builder->entity()->setRepositoryClass(DiscussionDoctrineRepository::class);
$builder->table('my_discussion');
$builder->increments('id');
$builder->string('title');
$builder->string('content');
$builder->string('cover');
$builder->string('createTime');
$builder->string('startTime');
$builder->string('endTime');
$builder->string('status');
$builder->string('hot')->columnName('hot_score');
$builder->oneToOne(User::class, 'user')->joinColumn('uid', 'uid');
}

above joinColumn not exist joinColumn method, is bug?

Using unique causes a specified key too long exception

When I add the unique constraint to my string field and run my migration, I get a SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes", Object(Doctrine\DBAL\Driver\PDOException)) exception.

$builder->string('email')->unique();

Without unique() the migration executes fine.

I have added Schema::defaultStringLength(191); to my AppServiceProvider.php file as per the Laravel documentation, but this does not appear to have resolved the issue.

I'm using:

  • Laravel 5.6
  • MariaDB 15.1
  • PHP 7.2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.