⚠ 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

Set Relation with where clause



arve
  • profile picture
  • Member

Posted 13 January 2018 - 14:27 PM

Hello. 

 

I'd like to set a where clause into my relationship. I've done this;

crud->setRelation('1', '2', '3', NULL, array('assembled'=>0));

Have also tried with table.assembled w/o any luck. 

 

Seems like I get all the values that are 1 as well as 0. 

 

Can someone help me on this one?

 

Thanks alot guys!


arve
  • profile picture
  • Member

Posted 14 January 2018 - 10:58 AM

Okay, so after some looking into the code I did find that it was the other way around. 

public function setRelation($fieldName , $relatedTable, $relatedTitleField, $where = null, $orderBy = null)

So I did move the order of the 2 last attributes, that did work perfect! 

 

But now I've got 2 columns that relates to the same table and then I get this error;

Message: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: 'tbl_tablename'

How do I manage to set an alias on these 2 or work around this, anybody knows?


web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 30 January 2018 - 04:33 AM

Hello @arve,

 

I will have a more specific example for you to help. Please let me know if that worked:
 

$crud->setRelation('office','offices','phone', [
    'offices.city = ?' => 'San Francisco'
]);

 

As you can see from the above code I am also including the table name (e.g. offices) and the syntax that I am writing the where is with the syntax here: https://www.grocerycrud.com/enterprise/api-and-function-list/where-3

 

Please let me know if you are still having issues.

 

Regards

Johnny


flowerbed333
  • profile picture
  • Member

Posted 22 February 2018 - 14:55 PM

Hi Johnny,

 

I have also purchased Grocery Crud Enterprise and I have an issue with usage of Set Relation (or Default Ordering) when I use the Syntax.

Example :

$crud->setRelation('lmc_title','lm_parameters','p_value', [
    'lm_parameters.p_type' => 'cust_title'
]);

 

I have no error when form is generated but I have One record Empty.

 

When I remove the Where clause ... All lines are generated but without filtering

 

Just for info I have the same problem with default Ordering

 
$crud->defaultOrdering('p_type', 'asc');
This Works !!!
 
$crud->defaultOrdering([
   'p_type' => 'as'
]);

This works Not ... But the 2 are similars. I am on XAMPP with GC Entr 2.5.

 

Could you give me a Trick ?