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

Feature: Create a collection when find() method is used. #308

Open
n0nag0n opened this issue Nov 13, 2020 · 0 comments
Open

Feature: Create a collection when find() method is used. #308

n0nag0n opened this issue Nov 13, 2020 · 0 comments
Labels

Comments

@n0nag0n
Copy link
Member

n0nag0n commented Nov 13, 2020

Context conversation from Slack:

Lucio 7:08 AM
https://fatfreeframework.com/3.7/sql-mapper#exists
Return TRUE if a given field is defined
bool exists( string $key )
It does not check if given entry exists, only checks if column exists, isn't it?
To check if entry exists will I have to $db->exec('SELECT EXISTS (SELECT * FROM table WHERE column=value)')?
I'm using hashids generated in PHP and I need to check if it already exists... (edited)

ikkez:rocket: 7:43 AM
it only checks if a fields / column is existing in your mapper

Blue 7:46 AM
load() returns false if nothing fits the filter, but in case you don't want to instanciate a new mapper to load data into it, count($db->exec("SELECT * FROM table WHERE column=value")) would evaluate to 0 if no entry was found (edited)

n0nag0n 7:53 AM
Yeah it's checking if the key exists, not if it exists and is not empty

Lucio 7:58 AM
@ikkez cleared. thank you 😉
@blue the thing is load() won't return at first find, it will scan the whole table I think. I'll also try findone().
So you're not in favor of EXISTS keyword? I've read somewhere it's faster...
Thank you the suggestions.
8:00
@n0nag0n Got it!

Blue 8:03 AM
I haven't used it a whole lot but in my mind, EXISTS isn't really appropriate to just find if there is a row that fits a certain criteria
8:04
It's more about joined tables, finding only the customers that have placed an order, that sort of thing

ikkez:rocket: 8:04 AM
to be more clear at this point, I think we could separate the datamapper and active record pattern within the mapper and create a repository / cellection model for find and single exist queries

n0nag0n 8:04 AM
I've been thinking about creating a collection when find() is used.

Blue 8:05 AM
I would love this. I don't like having a class with methods that return more of itself. I find it weird.

@ikkez ikkez added the v4 label Dec 13, 2020
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

2 participants