⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Why is it NOT allowed to have 2 fields with the same setRelation value?



larasmith
  • profile picture
  • Member

Posted 20 June 2018 - 05:47 AM

Hi Everyone!

 

I have a table that has two fields with the same setRelation Value reference.

 

The table structure is:

Table 1: tbldata

Fields:

d_id

d_Data

d_EncodedBy
d_ModifiedBy

 

Table 2: tblperson

Fields:

p_id

p_FirstName

p_LastName

p_Type

 

 

Both f_EncodedBy and f_ModifiedBy of table 1 should be referencing the table 2 through setRelation by:

$crud->setRelation('d_EncodedBy', 'tblperson', '{p_FirstName} {p_LastName}', ['p_Type <> ?'=>'1']);

$crud->setRelation('d_ModifiedBy', 'tblperson', '{p_FirstName} {p_LastName}', ['p_Type <> ?'=>'1']);

But an error is displayed which is as follows:

<p>Type: PDOException</p>
<p>Message: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'tblperson'</p>
 
Does anyone have the same experience?
Any workaround or ideas regarding this error?
 
Thanks in advance!  :)

 

 

 


Mugs321
  • profile picture
  • Member

Posted 24 June 2018 - 18:15 PM

Just posted what I think is the exact same problem/error/bug(?); linked below. One way I was able to get around the bug was to remove the filter at the end of one of the statements:

 

For example:

$crud->setRelation('d_EncodedBy', 'tblperson', '{p_FirstName} {p_LastName}');

$crud->setRelation('d_ModifiedBy', 'tblperson', '{p_FirstName} {p_LastName}', ['p_Type <> ?'=>'1']);

/topic/4338-error-in-setrelation-when-two-relations-point-to-same-table-and-both-use-where-clause/


larasmith
  • profile picture
  • Member

Posted 25 June 2018 - 00:58 AM

Hello Mugs321,

 

Thanks for trying it out.

I already did that but I need both to have filters so that the users won't have to see unneeded data from the drop-down.


Mugs321
  • profile picture
  • Member

Posted 25 June 2018 - 13:53 PM

I already did that but I need both to have filters so that the users won't have to see unneeded data from the drop-down.

 

We need the devs to weigh in.  Pretty sure it's a bug.  I have a few issues with the N2N relationship as well.