1

Why does the TYPO3 Extension Builder don't generate Foreign keys?

I've set some relations between the models, but in SQL Code there are noe FKs only colums for the Value of the key.

Does anyone can help me?

biesior
  • 55,576
  • 10
  • 125
  • 182
Felix
  • 5,452
  • 12
  • 68
  • 163

1 Answers1

3

Cite from Kartsen Dambekalns

It is a half-conscious design decision. Just look up the date when foreign key constraints where introduced in MySQL, and compare to when TYPO3 was 'born'.

Of course it would be great to add such references, especially since MySQL can always handle themm, even if the underlying storage engine doesn't handle them (in case of which they'll just be ignored).

(source)

Nothing changed till now, so you need to create foreign keys yourself after modeling.

Answer to comment:

how did you handle the relations between two tables? for example I've got a table people which relates to the table house with the column housenr

That depends on relation type of course (1:n, n:1, m:n, etc) and Builder supports creating relations in modeling tool perfectly. Keep in mind, that foreign keys are NOT required for keeping relations in TYPO3.

There are some rules described in TCA section of documentation, i.e. in mentioned case you can use select or group (with internal_type) type of field. For many-to-many relation also you'll need to create MM table. If you'll follow these documents, you can be sure, that in common backend editing form they will be handled properly.

As mentioned before Extension Builder supports creating different types of relations in its click-click modeling tool and it's worthy to spend some time to play with it to see how relations of different types are handled in TYPO3. It uses the same rules that are used in creating relations also in pre-extbase extensions. What's more Builder adds required methods to the models i.e. for getting, attaching and detaching MM objects of given relation field, therefore it's most important to model all your relations at start. In other case you'll need to write these methods manually (which is boring process)

biesior
  • 55,576
  • 10
  • 125
  • 182
  • thanks, okay then i gonna do this manually, can I do this in ext_tables.sql ist that okay? – Felix Dec 22 '14 at 14:20
  • TBH I never added foreign keys into TYPO3, so don't wanna to talk about it. I hope that you'll share your experiences when you'll do it. – biesior Dec 22 '14 at 15:04
  • how did you handle the relations between to tables? for example I've got a table people which relates to the table house with the column housenr and later I wanne render all houses with their related people? – Felix Dec 22 '14 at 15:15
  • Thanks again :) I gonna try it. One Question at least. Do you know how can get a relation to the typo3 FE Users? – Felix Dec 22 '14 at 16:45
  • Plain fe_user from TYPO3 or your model extending fe_user? (BTW. TYPO3 is written with uppercase, always ;)) – biesior Dec 22 '14 at 16:50
  • okay gonna try to write uppcase ;) My People Model shoud relate to the plain TYPO3 fe_user. Thanks alot! – Felix Dec 22 '14 at 17:02
  • You know what: create new question and describe there what's the case, especially if you want: __A)__ connect with fe_user as a relation (i.e. People.emploer = fe_user with uid 123) or __B)__ Model People extends fe_user table as you want to use this record type, but you need additional fields in it. Just answer depends on what's the goal, there are two different approaches – biesior Dec 22 '14 at 17:09
  • I've got already a question to this issue: http://stackoverflow.com/questions/27601254/foreign-key-to-typo3-frontend-user gonna edit it with more infos. – Felix Dec 22 '14 at 17:39