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

DboSource assumes data source has method queryAssociation #2066

Closed
ghost opened this issue Oct 11, 2013 · 3 comments
Closed

DboSource assumes data source has method queryAssociation #2066

ghost opened this issue Oct 11, 2013 · 3 comments
Labels
Milestone

Comments

@ghost
Copy link

ghost commented Oct 11, 2013

Created by skoranda (at gmail), 22nd Apr 2013. (originally Lighthouse ticket #3780):


The function queryAssociation in DboSource.php assumes that the data source instance has a queryAssociation() method in this code fragment:

if (!empty($fetch) && is_array($fetch)) {
if ($recursive > 0) {
foreach ($linkModel->associations() as $type1) {
foreach ($linkModel->{$type1} as $assoc1 => $assocData1) {
$deepModel = $linkModel->{$assoc1};
$tmpStack = $stack;
$tmpStack[] = $assoc1;

                            if ($linkModel->useDbConfig === $deepModel->useDbConfig) {
                                $db = $this;
                            } else {
                                $db = ConnectionManager::getDataSource($deepModel->useDbConfig);
                            }
                            $db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack);
                        }
                    }
                }
            }

and then again in this code fragment:

if ($recursive > 0) {
foreach ($linkModel->associations() as $type1) {
foreach ($linkModel->{$type1} as $assoc1 => $assocData1) {
$deepModel = $linkModel->{$assoc1};

                            if ($type1 === 'belongsTo' || ($deepModel->alias === $modelAlias && $type === 'belongsTo') || ($deepModel->alias !== $modelAlias)) {
                                $tmpStack = $stack;
                                $tmpStack[] = $assoc1;
                                if ($linkModel->useDbConfig == $deepModel->useDbConfig) {
                                    $db = $this;
                                } else {
                                    $db = ConnectionManager::getDataSource($deepModel->useDbConfig);
                                }
                                $db->queryAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $queryData, true, $fetch, $recursive - 1, $tmpStack);
                            }
                        }
                    }
                }

Not all data sources will have a queryAssociation method, especially when using models that do not use a relational database as the data store.

@ghost
Copy link
Author

ghost commented Oct 11, 2013

22nd Apr 2013, Jose Lorenzo Rodríguez said:


What it does assume is that for fetching association data other datasources must also be a database drivers. Otherwise it would make little sense trying to get them.

As a workaround for now, try to not fetch associations if you are using disimilar datasources. You can limit them by using $recursive = -1 in your model.

@ghost
Copy link
Author

ghost commented Oct 11, 2013

22nd Apr 2013, Mark Story said:


What should happen when you attempt to load associated data in a non-relational datastore? If queryAssociation() wasn't called then nothing would happen.

@lorenzo
Copy link
Member

lorenzo commented Oct 14, 2013

No follow ups on this issue after 6 months, closing

@lorenzo lorenzo closed this as completed Oct 14, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant