Welcome Guest, Not a member yet? Register   Sign In
CI 3, GAS ORM, multiple joins?
#1

Hi,

I have a function call inside a Gas Model:

Code:
$fields_user = alias_db_fields("User");
$fields_site = alias_db_fields("Site");

$prefixed_user = implode(", ", array_values($fields_user));
$prefixed_site = implode(", ", array_values($fields_site));

$this->select('EmailScheduling.*, ' . $prefixed_user . ', ' . $prefixed_site);
$this->join('User', 'EmailScheduling.user = User.id', 'left');
$this->join('Site', 'User.site = Site.id', 'left');
$this->limit($limit, $start)->order_by('EmailScheduling.id', "DESC");

$res = $this->all();


This results in this SQL and error:

A Database Error Occurred
Error Number: 42P01/7
ERROR: missing FROM-clause entry for table "User" LINE 3: LEFT JOIN "Site" ON "User"."site" = "Site"."id" ^
SELECT "EmailScheduling".*, "User"."id" as "user_id", "User"."client" as "user_client", "User"."name" as "user_name", "User"."domain" as "user_domain", "User"."logo" as "user_logo", "User"."productXML" as "user_productXML", "User"."registrationDate" as "user_registrationDate", "User"."disableEmailSending" as "user_disableEmailSending", "User"."carttype" as "user_carttype", "User"."productsUpdatedDate" as "user_productsUpdatedDate", "User"."emailURL" as "user_emailURL", "User"."retailSector" as "user_retailSector", "User"."ssl" as "user_ssl", "User"."ping" as "user_ping", "User"."orderRequestUrl" as "user_orderRequestUrl", "User"."isMailFunction" as "user_isMailFunction", "User"."pingDate" as "user_pingDate", "User"."emailTradingName" as "user_emailTradingName", "User"."encryption" as "user_encryption", "User"."shopifyDomain" as "user_shopifyDomain", "Site"."id" as "site_id", "Site"."client" as "site_client", "Site"."name" as "site_name", "Site"."domain" as "site_domain", "Site"."logo" as "site_logo", "Site"."productXML" as "site_productXML", "Site"."registrationDate" as "site_registrationDate", "Site"."disableEmailSending" as "site_disableEmailSending", "Site"."carttype" as "site_carttype", "Site"."productsUpdatedDate" as "site_productsUpdatedDate", "Site"."emailURL" as "site_emailURL", "Site"."retailSector" as "site_retailSector", "Site"."ssl" as "site_ssl", "Site"."ping" as "site_ping", "Site"."orderRequestUrl" as "site_orderRequestUrl", "Site"."isMailFunction" as "site_isMailFunction", "Site"."pingDate" as "site_pingDate", "Site"."emailTradingName" as "site_emailTradingName", "Site"."encryption" as "site_encryption", "Site"."shopifyDomain" as "site_shopifyDomain" FROM "EmailScheduling" LEFT JOIN "Site" ON "User"."site" = "Site"."id" ORDER BY "EmailScheduling"."id" DESC LIMIT 25
Filename: third_party/gas/classes/core.php
Line Number: 475


Looks like the first join() got overwritten by the second join(). How come? Does GAS not support multiple join() calls or is this a bug?

Any help appreciated.

Thanks.
Reply
#2

@xvision,

I don't know if it is a bug or just the way your adding the specific fields to the query. Why don't you try query binding ( https://codeigniter.com/userguide3/datab...y-bindings ). It might work better for you.
Reply
#3

(05-04-2020, 08:20 PM)php_rocs Wrote: @xvision,

I don't know if it is a bug or just the way your adding the specific fields to the query.  Why don't you try query binding ( https://codeigniter.com/userguide3/datab...y-bindings ).  It might work better for you.

How I am adding fields is irrelevant and using query binding has no relevance to joining tables. The problem is with the multiple calls to join(), and the fact that only one join statement is created.

I am using GAS ORM and my calls are inside a GAS ORM model. Note how I am calling $this->join(), rather than $this->db->join().

If I were to use a standard CI model this would not be an issue at all.
Reply
#4

(This post was last modified: 05-05-2020, 12:48 PM by php_rocs.)

@xvision,

I have never heard of GAS ORM. I was simply giving you a suggestion.
Reply
#5

According to the documentation you need to define a relation ship for the query.

Gas ORM 2.1 User Guide
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB