sunel / eav

Entity–attribute–value model (EAV) for Laravel Artisan
https://sunel.github.io/eav/
143 stars 39 forks source link

Cannot run command to create flat table #24

Open joaopmmartins opened 5 years ago

joaopmmartins commented 5 years ago

When I run the command 'php artisan eav:compile:entity product' to create the flat table I get the following error:

Compiling product entity. Creating flat table for products. in C:\Websites\eavproject\database/migrations/eav/products_flat.php Found 14 attributes.

In products_flat.php line 18:

syntax error, unexpected '(', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$'

And it creates the products_flat.php with the following syntax errors:

.... .... public function up() { Schema::dropIfExists('products_flat'); Schema::create('products_flat', function (Blueprint $table) { $table->(''); $table->string()('accessible_furniture_shape')->nullable(); $table->string()('item_weight_kg')->nullable(); $table->string()('strength_options')->nullable(); $table->string()('size')->nullable()->default('s'); $table->string()('length')->nullable(); $table->string()('width')->nullable(); $table->string()('item_weight_g')->nullable(); $table->int('featured_product')->nullable(); $table->string()('garden_tool_type')->nullable(); $table->string()('accessible_furniture_material')->nullable(); $table->int('garden_stool_arms')->nullable(); $table->string()('color_options')->nullable(); $table->string()('garden_tools_material')->nullable(); $table->string()('weight')->nullable(); }); }

.....

Any idea why is this happening? Thanks.

sunel commented 5 years ago

@joaopmmartins

What version of php and laravel are you using .

sunel commented 5 years ago

@joaopmmartins

Try running now

joaopmmartins commented 5 years ago

I still get the same error. I am using laravel 5.7.14 and PHP 7.2.4. I have the following attributes in the SQL Server (not mysql) database:

accessible_furniture_shape item_weight_kg strength_options size length width item_weight_g featured_product garden_tool_type garden_stool_arms color_options garden_tools_material weight tags

when i run the query php artisan eav:compile:entity product, it creates a class with syntax errors. It adds $table->(''); and $table->string(),...

<?php

use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration;

class ProductFlat extends Migration { /**

sunel commented 5 years ago

@joaopmmartins

Can you check if you have the latest code.

joaopmmartins commented 5 years ago

Hi sunel , Happy new Year!

Yes, I've updated the code but I am still having problems creating the 'product_flat' migration file. I am using a MS_SQL Database.

When I run the command "php artisan eav:compile:entity product"

it creates a migration file with errors. See the screenshot below.

In addition to all the attributes columns, can you please tell me what other columns should exist in the flat table so I can create them manually? Many thanks.

The migration file created:

image

The attributes table:

image

The entities table:

image

sunel commented 5 years ago

@joaopmmartins

Ok so this issue is in MS SQL.

I have never tested this package in MS SQL. I will try to test it.

Mean while here what the up migration for flat table looks like in MYSQL

/**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::dropIfExists('products_flat');
        Schema::create('products_flat', function (Blueprint $table) {
            $table->integer('id')->unsigned();
            $table->integer('entity_id')->unsigned();
            $table->integer('attribute_set_id')->unsigned();
            $table->timestamp('created_at')->nullable();
            $table->timestamp('updated_at')->nullable();
            $table->string('sku', 191)->nullable();
            $table->string('name', 191)->nullable();
            $table->boolean('search')->nullable();
            $table->text('description')->nullable();
            $table->point('location')->nullable();
            $table->dateTimeTz('located_at')->nullable();
        });
    }

Here is where this needs to be fixed.

https://github.com/sunel/eav/blob/51d64040a074fb5dec5c2ebb2b714901a9daef0d/src/Flat/Entity/Complier.php#L85_L161

Let me know if where able to find the issue

I presume the information_schema has different result.

https://github.com/sunel/eav/blob/51d64040a074fb5dec5c2ebb2b714901a9daef0d/src/Flat/Entity/Complier.php#L182_L186

joaopmmartins commented 5 years ago

It gave me error :(:)

SQLSTATE[IMSSP]: Tried to bind parameter number 2101. SQL Server supports a maximum of 2100 parameters.

I have additional columns in my product table (not in the eav tables), including name, description, metakeywords, ... I defined those attribute as 'backend_type' => 'static' in the attributes table. Do I have to create the same columns in the flat table as well?

sunel commented 5 years ago

Yes, Flat table are normalized form of all the tables.

leduyhoang1994 commented 4 years ago

@sunel hey, i found this error ocured when i added no attributes to the entity. I use only static attributes for initial. This line https://github.com/sunel/eav/blob/51d64040a074fb5dec5c2ebb2b714901a9daef0d/src/Flat/Entity/Complier.php#L158 Please update it like "if there are no attributes then adding no "," after the schema".

$schema = (new SchemaParser)->parse($table->implode(',').(count($attributes) > 0 ? ',' : '').$attributes->implode(','));

Thanks !!