Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NTDB joining tables on different key as primary key #114

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

NTDB joining tables on different key as primary key #114

wants to merge 3 commits into from

Conversation

apincik
Copy link

@apincik apincik commented Dec 30, 2015

Table 'e_country'

id (int)
e_country_code (varchar(2))
name (varchar(50))

Indexes: PK(id), UNIQUE(e_country_code)

Second table:

Table 'p_product'
id (int)
country (varchar(2))

Indexes: PK(id), INDEX(country)
FK: country -> e_country(e_country_code)

1:N relation
For example calling:

$this->dbContext->table("p_product")->select("p_product.*, country.e_country_code AS c_title");

The result:

SELECT `p_product`.*, `country`.`e_country_code` AS `c_title`
FROM `p_product`
LEFT JOIN `e_country` `country` ON `p_product`.`country` = `country`.`id`

If calling ref() on activeRow, the result in where clause is

`id` IN ("string", "string", "...")

Now, it gets p_product foreign keys from schema and replaces primary_key with column name on referenced table. So finall result will be:

LEFT JOIN `e_country` `country` ON `p_product`.`country` = `country`.`e_country_code`
...
`e_country_code` IN ("string", "string", "...") //ActiveRow->ref()

…eRow, it does lookup for foreign key column name in referenced table, not just primary key of referenced table
…on ActiveRow, it does lookup for foreign key column name in referenced table, not just primary key of referenced table"

This reverts commit ec9ef62.
…ow, it does lookup for foreign key column name in referenced table, not just primary key of referenced table.
@dg dg force-pushed the master branch 4 times, most recently from 0771c2f to 425ad23 Compare April 21, 2016 13:03
@dg dg force-pushed the master branch 2 times, most recently from 59a6661 to b660054 Compare May 30, 2016 14:28
@dg dg force-pushed the master branch 2 times, most recently from 5c87d56 to d9fd67a Compare June 27, 2016 23:11
@dg dg force-pushed the master branch 13 times, most recently from 44a230d to 829b936 Compare October 18, 2016 13:01
@dg dg force-pushed the master branch 2 times, most recently from b74e9fb to b2e321a Compare December 3, 2016 18:55
@dg dg force-pushed the master branch 4 times, most recently from abe9849 to 9358712 Compare June 29, 2017 15:38
@dg dg force-pushed the master branch 7 times, most recently from f1a9aa2 to ec7a207 Compare July 26, 2017 21:39
@dg dg force-pushed the master branch 14 times, most recently from 1ea2fe2 to f4d7fc0 Compare March 23, 2018 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant