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

Automatically set lookupFields based on the entities identifier fields #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lsmith77
Copy link

This is an untested change and the PR is more meant to start a discussion on this since this is kind of a BC break.

Inside the class itself the following code uses the lookupFields:

            if (!empty($this->lookupFields)) {
                $lookupConditions = array();
                foreach ($this->lookupFields as $fieldName) {
                    $lookupConditions[$fieldName] = $item[$fieldName];
                }

                $object = call_user_func($this->lookupMethod, $lookupConditions);
            } else {
                $object = $this->objectRepository->find(current($item));
            }

The else case would now of course never be reached. Now $index defaults to null in the constructor. We could of course make it even more flexible by optionally also supporting a boolean to determine if to use the old approach or if to use the new approach added in this PR.

wdyt?

@lsmith77
Copy link
Author

@ddeboer ping :)

@Baachi
Copy link
Contributor

Baachi commented Dec 7, 2017

Hey @lsmith77,

nice addition! But i'm not really sure if a 5th parameter is such a good design.
WDYT about to extract the lookup logic to a seperate class, which is than passed to the constructor.

@lsmith77
Copy link
Author

lsmith77 commented Dec 7, 2017

@Baachi how to handle BC in such a case?

Maybe adding a factory method for the different use cases?
DoctrineWriter::createX() ?

@ddeboer
Copy link
Member

ddeboer commented Dec 8, 2017

WDYT about to extract the lookup logic to a seperate class, which is than passed to the constructor.

Good idea: see #11.

While it is a slight BC break, I’m okay with removing the ->find(current($item)) and changing the default behaviour to using the identifier field names, because it’s more explicit than relying on the first value in $item (whatever that may be) to match the primary key.

So @lsmith77, could you please add a test case?

@ddeboer
Copy link
Member

ddeboer commented Dec 10, 2017

Possibly fixes portphp/portphp#50.

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.

3 participants