Results 1 to 7 of 7

Thread: pid as foreign key

  1. #1
    User
    Join Date
    11-23-09.
    Location
    Valais, Switzerland
    Posts
    77

    Default pid as foreign key

    Hello,

    I am currently creating a new module. Don't I understand the use of the pid! Is it a foreign key? Why the name is pid and not the name of the foreign table + _fk? If I have two keys foreign on a table I can't name them both pid... so it is not working.

    can you explain me?

    Thanks

  2. #2
    User
    Join Date
    06-19-09.
    Posts
    328

    Default Re: pid as foreign key

    you can use foreign keys without having a pid

    see for example the tl_form table. it has a jumpTo field which is related to tl_page. tl_form doesn't have a pid field.

    if you need additional help please post your database schema (please, only the relevant part )
    Consulenza Contao CMS https://www.intco.it

  3. #3
    User
    Join Date
    11-23-09.
    Location
    Valais, Switzerland
    Posts
    77

    Default Re: pid as foreign key

    Ok, thanks for information.

    The database script is really sensitive. It is very difficult to test to add some new data. The typolight install.php script do not accept every type or constraint. I have some more questions :

    1. why are the "date" as "Int" registred? can we use the "Date" and "DateTime" type (for the calendar picker)?
    2. Can we use Constraint? delete on cascade?

  4. #4
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: pid as foreign key

    Typolight uses id/pid and tstamp in all modules....
    pid is used when you set up parent/child tables so Typolight can track the parent table...and delete child records when a parent is deleted for example.
    tstamp is int(10) because time/dates are converted to Unix Timestamp before saving.
    Any custom modules should use these 3 fields in their tables, but its up to you how you store anything else.

    Don't know about constraint/cascade sorry

  5. #5
    User
    Join Date
    11-23-09.
    Location
    Valais, Switzerland
    Posts
    77

    Default Re: pid as foreign key

    Quote Originally Posted by ramjet
    ...and delete child records when a parent is deleted for example.
    hum, ok there is already a "Delete on cascade" inside Typolight.

    Thanks

  6. #6
    New user
    Join Date
    07-09-10.
    Posts
    2

    Default Re: pid as foreign key

    can we use two parent-child relation on the same table, for example i have users table which is child table of company and programs so how can i set this relation (user belongs to company, user belongs to program) since there is one pid field in users table?

  7. #7
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: pid as foreign key

    Hi Kerim46,
    The "pid" field of a record matches the "id" field of the parent record.

    A record can only have one parent, but can have many children.... which is why in the DCA 'config'=>'ctable' is an array (to hold more than one child table reference), while 'config'=>'ptable' is not.

    So no, you cannot do it that way.... its probably a matter of using SQL joins and/or callbacks.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •