Closed paomian closed 6 years ago
It's not, it adds fields on top of fields defined in the entity:
(sql-only (select user (fields :a)))
;;=> "SELECT \"user\".\"a\", \"user\".\"b\", \"user\".\"c\", \"user\".\"a\" FROM \"user\""
I means how i change the default field which be select. for example:
(select user (fields :a))
just select user.a from user
not add default field such as b
c
.
@paomian My solution to the same problem was creating a function like this:
(defn limit-fields
[ent & fields]
(assoc ent :fields fields))
Then, you can use this in your queries to override the fields.
(select user
(limit-fields :a)) ; Will now only select user.a
Or just don't define them as entity-fields
if you don't want to always include them. This has been also discussed in #251.
I started using Korma earlier today and I ran into the same misunderstanding. Having read the other issue, I like the fact that Korma's query manipulation functions are additive-only, but I think some extra documentation might be helpful. Specifically, I'd like it if the documentation for select queries mentioned that fields specified in fields
are selected in addition to those specified in entity-fields
.
I agree that the documentation can be improved. I'll be happy to take a pull request improving docstrings and sqlkorma.com documentation.
This issue seems to have been addressed and so I am going to close it.