-
Notifications
You must be signed in to change notification settings - Fork 90
Extended order_by and bugfixes #135
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
Conversation
note that order_by can operate on expressions, not just attribute names. For example, if I wish to sort so that name='Fabian' comes before all others I would need to say, according to the proposed syntax: relation.fetch.order_by('name="Fabian"=DESC', 'trial') This does not seem like good syntax. Plus the word DESC is hardly PEP8-friendly. How about tuples relation.fetch.order_by(('name', True), 'trial', ('stimulus', True)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for copy_first
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We thought that it would make more sense for each operation on the fetch
object to return a new fetch
object rather than modifying the object in place. Since fetch
object in itself is very cheap, this shouldn't be a real over head. copy_first
is a decorator that modifies the decorated method to work on and modify the copy of the object, supporting this idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use copy.copy
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy.copy
does not copy the dict behavior
. The function deepcopy
would copy _relation
as well which seemed like an overkill. That's why I introduced a copy constructor and used a decorator to tell the function, that I'd like self
copied. Having the elements of behavior
as object attributes wouldn't solve the problem, since some of the values of behavior
are lists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why do we need to copy the object in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i have looked into other modules and, yes, things like these usually copy the object. I am merging this PR.
Extended order_by and bugfixes
relation.fetch.order_by
allows for individual sorting arguments now. I removed the kwargdescending
. The new syntax isrelation.fetch.order_by('name DESC', 'trial', 'stimulus DESC')
. If the sorting argument is omitted, ASC is set by default.relation.fetch.apply
function. It is not needed at the moment and simplified the syntax substantially. Additionally, it might cause confusion, since something likerelation.fetch.apply(myfunc).order_by('stimulus')['name']
suggests that the function is applied in the beginning, but it would have been applied at the end.FetchQuery
toFetch
andFetch1Query
toFetch1
limit_by
tolimit_to
. Dimitri actually preferslimit
, but I thinklimit_to
is more consistent withorder_by
.