Is there a way to configure the MJoin class in order to deal with the absence of an identity field?

Is there a way to configure the MJoin class in order to deal with the absence of an identity field?

clazetteclazette Posts: 26Questions: 7Answers: 2

I have Mjoin configured to display a list of checkboxes based on a many-to-many relationship. On create, I am receiving a FK violation exception due to the fact that one of the parent table's PK is not an identity field. This is a SQL Server implementation.

This is an issue because, before Editor can insert the associate records, it executes a SELECT@@IDENTITY which returns null. Thus, those associate table inserts die.

Is there a way around this that doesn't involve changing the field to an identity because that just causes a whole host of other issues.

Thanks,
Chad

This question has an accepted answers - jump to answer

Answers

  • clazetteclazette Posts: 26Questions: 7Answers: 2
    Answer ✓

    I solved the issue by adding the third parameter, $pkey, of the Editor class' constructor. In my case, the ID column is the PK so here is the constructor.

    Editor::inst( $db, 'tablename', 'ID' )
    
  • allanallan Posts: 61,821Questions: 1Answers: 10,127 Site admin

    Hi Chad,

    Good to hear you found the solution for this. Thanks for posting back.

    Allan

This discussion has been closed.