-
Notifications
You must be signed in to change notification settings - Fork 58
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
SELECT QUERY With specific fields. #33
Comments
|
You cannot do something like |
That is not allowed for now. |
you plan to put it later or not ? I've got table with many rows and I want to select only 5 rows of them, why should I perform 2 select request than one ? |
I guess when you say rows, you mean columns (otherwise it can achieve with limit()). The reason is when you select a post, you get a Row instance representing that post. If you select again the same post, instead performing a new select, you get the previous Row instance, so the changes saved in one side will affect to the other side. If you select a post limiting the amount of columns, you wont get the remaining columns in the future, because the same row will be used always. If you never need these columns, a workaround is modify the database scheme to hidden these columns in simplecrud. For example: $scheme = $db->getScheme();
unset($scheme['table']['fields']['column1']);
unset($scheme['table']['fields']['column2']);
$db->setScheme($scheme); Now, |
it would be better to have columns directly like you do whith update/insert method like you did here:
and a select (that is missing)
to display only the needed fields. Your method above is not the best approach if you deal with a row that have multiples columns. One line and that'all we need. Make that magical please ;) |
+1 This example not working TOO: |
I'm not sure if this can be implemented easily in Simple Crud. As explained above, this can generate future bugs. For example: $client = $db->clients->select()->columns('name')->where('id = ', 2)->get();
$client = $db->clients->select()->where('id = ', 2)->get(); SimpleCrud always save the rows in a internal cache, so the next time that you select the client with id 2, the cached row is returned. In this example, the second |
Ok, And what about LEFT JOIN?
|
This should work: // Select the first table
$leads = $db->leads->select()->get();
// Load the clients of the selected rows
$leads->clients;
// Now you can iterate:
foreach ($leads as $lead) {
foreach ($lead->clients as $client) {
var_dump($client);
}
} The $leads = $db->leads->select()->column("(field1 + field2) as result")->get();
foreach ($leads as $lead) {
var_dump($lead->result);
} |
Hello,
I was wondering how to make a SELECT query with specific fields.
I mean how can I do something like this:
SELECT field1, field2 FROM table;
Thank you for your answers!
The text was updated successfully, but these errors were encountered: