Make flatten() run limit(1) #14

Closed
opened 2023-11-02 10:32:00 +01:00 by vlw · 0 comments
vlw commented 2023-11-02 10:32:00 +01:00 (Migrated from codeberg.org)

I'm considering making the MySQL->flatten() method also run MySQL->limit(1) since it has the same effect.

Example:

// Flatten returned array to first entity if set
public function flatten(bool $flag = true): self {
	$this->flatten = $flag;

	// Set LIMIT 1 if flatten flag is enabled, or unset if turned off
	$this->limit($this->flatten ? 1 : null);

	return $this;
}

I'm not sure tho if this could have other unwanted side-effects when for example removing the flatten flag with flatten(false). LIMIT would still be 1. Or if we simply remove the LIMIT all together, any LIMIT set before this will be forgotten and wiped and I'm not sure either if it's worth storing the last LIMIT in an instanced property.. It might be overkill.

I'm considering making the `MySQL->flatten()` method also run `MySQL->limit(1)` since it has the same effect. Example: ```php // Flatten returned array to first entity if set public function flatten(bool $flag = true): self { $this->flatten = $flag; // Set LIMIT 1 if flatten flag is enabled, or unset if turned off $this->limit($this->flatten ? 1 : null); return $this; } ``` I'm not sure tho if this could have other unwanted side-effects when for example removing the flatten flag with `flatten(false)`. `LIMIT` would still be `1`. Or if we simply remove the `LIMIT` all together, any LIMIT set before this will be forgotten and wiped and I'm not sure either if it's worth storing the last LIMIT in an instanced property.. It might be overkill.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
vlw/php-mysql#14
No description provided.