-
Notifications
You must be signed in to change notification settings - Fork 223
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
Restricting fields in select isn't possible after defining them on the entity #251
Comments
- Adapted syntax - The moves.game_id column got renamed to moves.games_id to match the referenced table name (games) - Removed some fields declarations because of: korma/Korma#251
This is how |
Well this wasn't the behaviour in 0.3.5. I used to have the fields defined and setting fields in the query would ignore the default fields from If this is the new way that this feature should work, then it should be documented. The current documentation (http://sqlkorma.com/docs#select) describes the previous behavior:
|
I have to agree with @mapleoin on this : this behavior is not documented and so tricked me into the same problem. I don't understand your answer @immoh in fact, maybe I've missed something ? |
@mapleoin: I assume you're talking about 0.3.0-RC5. Looks like back then (defentity games
(fields :board :white :black :moves))
;;=> (var user/games)
(sql-only (select games))
;;=> "SELECT \"games\".* FROM \"games\"" Behavior of (-> (select* :games)
(fields :board)
(fields :moves)
select
sql-only)
;;=> "SELECT \"games\".\"board\", \"games\".\"moves\" FROM \"games\"" I agree that the documentation could more clear about this. PRs welcome :) |
Right, it was 0.3.0-RC5. Ok, I'll look more into this and try to send a PR. |
Ok, so I've opened korma/sqlkorma#10 to address this in the documentation. However, after writing that, I am even more convinced that this is a bug because if it's hard to document then it's a bug :). AFAICS the behaviour of the I think the right behavior should be to only use the On a related note, @immoh, is it right that using |
Would it help to stop saying "default fields" and document that I thought the confusion was mostly about Yeah, based on my quick check in repl It looks like |
Right, but I still find that behaviour awkward. Why would you want to have fields defined on the entity included in all queries with no option to override them? I could see that being useful if we redefined the way we look at entities. If instead of mapping one to one with tables they would just be one view of a table and the documentation would encourage defining many entities on the same table just for the purpose of making some queries easier. But that doesn't seem to be the intention right now.
Right. Perhaps I'm coming at this with the wrong mindset (python/ruby ORMs), but yes, I would expect that if only one set of fields is specified in a query, then only those columns are returned. Returning extra columns which were defined somewhere else is a bit of a magic behavior (unless |
In Korma, all query manipulation functions add on top of existing query instead of overriding existing values. I'm sorry to hear that you find this behavior magic or unintuitive but I don't think the behavior is going to change in near future. |
I am running into the exact same issue. I just recently started implementing korma into my project and don't see the point as well why there is no option available to override fields or limit behavior. The way I see it, it is supposed to work like this: Taking a look at different database mappers, for instance in django: Entities define how a entity is displayed in the database, including all it's fields and relations it has to other entities. These fields are more a summary of what the entity consists of rather than a list of default values. Just because I have a Having I'm giving my +1 to changing this functionality back the way it makes more sense. Change the current behavior to |
I too am surprised by this behavior. Reading the documentation, I assumed that |
Entities do not define fields with entitiy-fields anymore. This had the side effect of not allowing leaving out columns in select queries. See korma/Korma#251
@fbauer: You shouldn't define them as entity fields if you don't want them in the output. |
@immoh: I changed my code and don't define entity-fields anymore.
That would help. Changing "default fields" to "fields that will be included in all select queries" would have solved the ambiguity for me. |
Can rename entity-fields to default-fields? it will more clear. |
Hi, Does this mean that you cant perform aggregate functions (GROUP, SUM) on tables with entity fields? |
I'm agree with #251 (comment), |
I'm going to leave this issue open. The feature as it currently exists clearly causes confusion, as evidenced by the fact that people keep filing it as a bug (ref. #286 and #340). I personally thought it was a bug when I ran into it about 9 months ago. I also think the way setting fields on an entity currently works is just not an ideal interface. If we're going to argue that it should continue to function this way as a matter of composability then we should provide a mechanism for people to exclude those fields easily when making entity queries. |
I have the following entity defined:
Now when I try to do a select with just one column I get:
IMHO this is a bug, as the expected output is:
The text was updated successfully, but these errors were encountered: