Git Product home page Git Product logo

Comments (6)

deiucanta avatar deiucanta commented on August 25, 2024

@robsontenorio good idea :)

It might be even better to have it in the same method

Field::make('user_id')->unsignedInteger()->references('users.id');
Field::make('user_id')->unsignedInteger()->references('users', 'id');
Field::make('user_id')->unsignedInteger()->references(User::class, 'id');

What about deleting on cascade? Do you use db level deletion or you delete related entities in the app?

from laravel-smart.

robsontenorio avatar robsontenorio commented on August 25, 2024

I don’t use DB level deletion.

I just suggest the same syntax of Laravel migration just for consistency with well known methods from Laravel.

from laravel-smart.

robsontenorio avatar robsontenorio commented on August 25, 2024

@deiucanta I think this is a pretty important issue. A must have.

Without this we can't guarantee FK constraints out of box for smart migrations, and would be necessary do it manually editing files (boring).

About syntax i do prefer.

Field::make('user_id')->unsignedInteger()->references('users.id');

I'm not expert on databases. But, on this first version we can consider that FK's will always be unsignedInteger() type (i have never used other type than this). So, this statement can be suppressed by adding it on "field types" by default when using references().

Field::make('user_id')->required()->unsignedInteger()->references('users.id')->label("User");
Field::make('user_id')->required()->references('users.id')->label("User");

Can you handle it?

from laravel-smart.

deiucanta avatar deiucanta commented on August 25, 2024

The issue here might be if the user id is not unsignedInteger. It can be string, integer (with negative values), unsignedBigInteger, etc. How to handle that?

I created REST APIs in Laravel that used UUIDs for the primary key. I also can imagine someone having big tables and using bigIncrements instead of increments.

from laravel-smart.

deiucanta avatar deiucanta commented on August 25, 2024

The diff algorithm is just a proof of concept and I'd rather refactor it than patch it to make foreign keys work. Especially for dropping them.

We also didn't touch the requirement of having indexes on multiple fields. That would also impact the diff algorithm, the migration generation, and even the API for field definition.

I'd say we should address all these issues together to get the best outcome.

from laravel-smart.

robsontenorio avatar robsontenorio commented on August 25, 2024

from laravel-smart.

Related Issues (19)

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.