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

Unexpected behaviour of fields function #231

Closed
bilus opened this issue May 26, 2014 · 2 comments
Closed

Unexpected behaviour of fields function #231

bilus opened this issue May 26, 2014 · 2 comments

Comments

@bilus
Copy link

bilus commented May 26, 2014

I'm only beginning my journey with Korma so pardon me if I'm being pathetically dumb. :)

I found the following behaviour to be very counter-intuitive:

(defentity user
  (entity-fields :id :name))  

(-> 
  (select* user) 
  (fields :id) 
  (as-sql))

The result is:

=> SELECT "user"."id", "user"."name", "user"."id" FROM "user"

Note that user.id appears twice! I definitely expected the call to fields to let me create a list of fields for the SELECT statement. Instead, it vconcats them to the default fields in entity (:fields user).

Of course one can dissoc the defaults like this:

(-> 
  (select* user)
  (dissoc :fields)
  (fields :id) 
  (as-sql))

=> SELECT "user"."id" FROM "user"

This is a bit cumbersome and not quite something you expect to write.

So, is there a more idiomatic way to do what I need or is it something that the library could improve upon?

@immoh
Copy link
Member

immoh commented May 27, 2014

The purpose of entity-fields is to set the default fields that are always returned. As I see it, fields shouldn't change this but allow you to add more fields on top of default fields.

There has been discussion about adding functions to the API for resetting order/fields: #225

@bilus
Copy link
Author

bilus commented May 27, 2014

Thanks for the explanation, I certainly see the point of that.

On Tue, May 27, 2014 at 2:22 PM, Immo Heikkinen [email protected]:

The purpose of entity-fields is to set the default fields that are always
returned. As I see it, fields shouldn't change this but allow you to add
more fields on top of default fields.

There has been discussion about adding functions to the API for resetting
order/fields: #225 #225


Reply to this email directly or view it on GitHubhttps://github.com//issues/231#issuecomment-44268052
.

@immoh immoh closed this as completed Jun 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants