Giter Site home page Giter Site logo

Comments (7)

gdbhosale avatar gdbhosale commented on August 28, 2024

Hi @mgazelle,

I appreciate your thought, but we have to integrate it manually after code generation.
Different developers will have different thoughts over this as we have facility to edit our module field after creation.
Let me know if you have a good plan for implementation strategy. I would appreciate that.

Best Regards,

from laraadmin.

mgazelle avatar mgazelle commented on August 28, 2024

I have changed this on my site to auto create the migration blocks you would create by hand in a migration file. All you have to do, is translate the field definition in the proper syntax of a migration file (Schema::create) and then append the foreign keys at the end.

I do not store the field definition in a table as mentioned in another issue post. I just translate the fields in proper laravel code which will adhere to Laravel docs and definitions.

I do not think personally a generator should write definitions back into the app database.

Another approach would be to reverse the DB schema. This way you create the DB and you are done with the rest.

from laraadmin.

gdbhosale avatar gdbhosale commented on August 28, 2024

@mgazelle @slozano95

Check inbuilt migrations.
Can we use relationship manual way like that ?

File: 2014_12_01_000000_create_uploads_table.php

if (Schema::hasTable('users')) {
    Schema::table('uploads', function ($table) {
        $table->foreign('user_id')->references('id')->on('users');
    });
}

It is also possible to reverse migrate this by putting similar syntax at end of up() method.

Let me know.

from laraadmin.

mgazelle avatar mgazelle commented on August 28, 2024

@gdbhosale
This is in fact the Laravel way doing it. Relationship is in my opinion the most critical feature in the whole package. This would improve the package a lot. My suggestion would be:

  1. check if the relationship is implemented in the DB (from the migration file or the module definition)
  2. if not check the migration file to make sure it has not been appended
  3. generate a new laravel migration file including just the foreign keys in the up method

If the relation is defined during the generation of the module then just append it to the up method

from laraadmin.

gdbhosale avatar gdbhosale commented on August 28, 2024

@mgazelle @slozano95 I have completed with auto foreign key setting through Migrations as well as GUI. We can as well shift foreign keys from one table to another without fuss.
I am not very sure about way i have implemented it. Please go through the code.
Let me know your view. Hey @mgazelle You were quite right about this 👍
Please report problems soon if they exists.

============ Module::create_field_schema (line 296) ============
$foreign_table_name = str_replace("@", "", $field->popup_vals);
if($update) {
    $var = $table->integer($field->colname)->unsigned()->change();
    if($field->defaultvalue == "" || $field->defaultvalue == "0") {
        $var->default(1);
    } else {
        $var->default($field->defaultvalue);
    }
    $table->dropForeign($field->module_obj->name_db."_".$field->colname."_foreign");
    $table->foreign($field->colname)->references('id')->on($foreign_table_name);
} else {
    $var = $table->integer($field->colname)->unsigned();
    if($field->defaultvalue == "" || $field->defaultvalue == "0") {
        $var->default(1);
    } else {
        $var->default($field->defaultvalue);
    }
    $table->foreign($field->colname)->references('id')->on($foreign_table_name);
}

Thank you guys...

from laraadmin.

echemik avatar echemik commented on August 28, 2024

How to u se this? Do you plan to implement manage relations n:m (many to many) via GUI? Very useful will be also show related records in record view. Eg. Organization has many (3) Contacts. I see Organization and below section "Related Contacts" with this 3 records - its fundamental to CRM.

from laraadmin.

gdbhosale avatar gdbhosale commented on August 28, 2024

Hi @mgazelle,

Foreign key linking with respective table is automatically handled by Custom Migrations.

You only need to write methods in Models.

Best Regards,

from laraadmin.

Related Issues (20)

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.