kirkbushell / eloquence

A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.
MIT License
537 stars 58 forks source link

Correct field types for pivot tables #48

Closed simplenotezy closed 8 years ago

simplenotezy commented 8 years ago

What is the correct formatting for pivot tables? Usually, with normal integer ID's it would generate:

    Schema::create('domain_user', function (Blueprint $table) {
        $table->integer('domain_id')->unsigned()->index();
        $table->foreign('domain_id')->references('id')->on('domains')->onDelete('cascade');
        $table->integer('user_id')->unsigned()->index();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->primary(['domain_id', 'user_id']);
    });

I'm thinking below should be enough (simply changing to string 36 and removing unsigned):

    Schema::create('domain_user', function (Blueprint $table) {
        $table->string('domain_id',36)->index();
        $table->foreign('domain_id')->references('id')->on('domains')->onDelete('cascade');
        $table->string('user_id',36)()->index();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->primary(['domain_id', 'user_id']);
    });

But that generates the following error:

SQLSTATE[HY000]: General error: 1215 Cannot add foreign key const
raint (SQL: alter table `domain_user` add constraint domain_user_
domain_id_foreign foreign key (`domain_id`) references `domains`
(`id`) on delete cascade)
kirkbushell commented 8 years ago

Issues should be directly related to any problems that arise within the library, not general questions regarding SQL migrations. I'd recommend reading up SQL table schemas regarding UUIDs.

simplenotezy commented 8 years ago

True, but what about adding this basic information to the documentation?

kirkbushell commented 8 years ago

There's plenty of information about how to best store UUIDs on the various SQL platforms :)

simplenotezy commented 8 years ago

Sure. But why not include the basiscs in the documentation?

kirkbushell commented 8 years ago

Should I also include documentation on how to write PHP?

Documentation is there for the library, nothing more. You're expected to know certain things if you want to use some of its features.