-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Codeigniter\Entity - Fix ToArray datamap #3508
Codeigniter\Entity - Fix ToArray datamap #3508
Conversation
Additional information regarding this commit is provided in PR
This PR is not final yet. This is just to understand the issue. I'm thinking about more elegant solution to avoid having all those checks and do everything in single foreach loop. As datamap already works on magic getter the idea is to properly prepare keys and then run foreach loop to get values using those keys. The way to prepare those keys will be done like this
Let me know what you think about doing it this way |
I've submitted another commit which will handle this by processing keys first |
I like this. Nice and clean solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much cleaner! Elegant solution. I think you've recreated an existing function, but let me know if I've misunderstood that.
protected $datamap = [ | ||
'bar' => 'foo', | ||
'foo' => 'bar', | ||
'original_bar' => 'bar', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@najdanovicivan
Each property (array key) in the Entity has a value, so if the column bar
has two properties,
we need to discard one value when inserting to database.
The $datamap
seems to be invalid. Am I something wrong?
You added the swapped case, but do you really need the use case? If we prohibit it, the Entity would be simpler. |
Description
There are couple of issues with the way datamap works
I've added the getSwappedEntity() method which returns the entity which is affected by all those issues.
Checklist: