List of Tables

0

Creating my migrations in Laravel I had the following doubt:

I have these two tables:

Used

  • ID
  • MARK_NAME_ID
  • MODEL
  • YEAR

TRADEMARKS

  • ID
  • NAME

migration to save the tag ID I would do so:

$table->integer('marca_id')->unsigned();
$table->foreign('marca_id')->references('id')->on('marcas');

All information is stored through a form. And if I want to save USADOS to column NOME_MARCA_ID Nome and not ID would be possible?

    
asked by anonymous 28.08.2016 / 15:59

2 answers

0

This practice, in addition to Mysql does not allow, does not make much sense. First, in order to relate two tables, the reference field must necessarily have identical properties. Second, you can generate an integrity error if in Marcas the NOME field can be repeated with the same data in another record.

The best way to do this is by the key, which in this case is id , so that you can retrieve all other data from the relationship, including Nome , which is the field in question.

I hope I have helped

    
29.08.2016 / 23:11
0
  • According to 'Entity Integrity', it is not correct. It should be a relationship with the primary key of the table that will get the 'Brand'.
  • A query with 'Inner Join' already helps get the 'Brand' name.

    Any questions, we're there.

  • 30.08.2016 / 05:20