Skip to content

Conversation

leviathan747
Copy link
Collaborator

this method returns a sorted set based upon the specified attribute name.
if the class has no attribute by that name, an exception is raised.

@coveralls
Copy link
Collaborator

coveralls commented Jun 12, 2018

Coverage Status

Coverage increased (+0.03%) to 81.263% when pulling c0056d1 on leviathan747:ordered_by into 041902f on xtuml:master.

xtuml/meta.py Outdated
if not hasattr(y, attr):
raise MetaException("Class '%s' has no attribute '%s'" % (get_metaclass(y).kind, attr))

return cmp( tuple(getattr(x, attr) for attr in self), tuple(getattr(y, attr) for attr in self) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

superfluous spaces within parenthesis group

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


def test_select_many_ordered_by(self):
m = self.metamodel
q = m.select_many('S_DT', None, order_by('Name', 'DT_ID'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking, it should be possible to to make the where_clause and order_by argument less independent on the order in the parameter list. Something like this:

def select_many(kind, set_modifiers*):
s = map(apply_set_operator, set_modifiers)
return s

then you could type:
q = m.select_many('S_DT', order_by('Name', 'DT_ID'), where(...))
or
q = m.select_many('S_DT', where(...), order_by('Name', 'DT_ID'))
or
q = m.select_many('S_DT', order_by('Name', 'DT_ID'))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm. I will give this some thought. Of course the difficulty is how to implement the 'apply_set_operator' part

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map() might have been a bad idea. I slapped together a gist demonstrating one way of doing it. needs some cleaning though...

See https://gist.github.com/john-tornblom/21eca04788c3980778039bf91866e7dd

xtuml/meta.py Outdated
>>> from xtuml import order_by
>>> m = xtuml.load_metamodel('db.sql')
>>> inst = m.select_many('My_Modeled_Class', None, order_by( 'Name', 'Number' ) )
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, superfluous spaces within parenthesis group.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@john-tornblom
Copy link
Contributor

Python3 seems to fail on travis, see https://api.travis-ci.org/v3/job/391935957/log.txt

I was thinking of altering your patch a bit anyway to something like this: https://gist.github.com/john-tornblom/21eca04788c3980778039bf91866e7dd). I can accept the patch and rework it myself, or do you wanna give it a go?

@leviathan747
Copy link
Collaborator Author

You can either accept mine and alter as you wish or you could submit a PR to my fork and I will service it (and then this PR would get automatically updated).

…rators.

This also fixes python3 issues due to deprecation of the cmp key to sorted()
@john-tornblom
Copy link
Contributor

My repo was created before xtuml/pyxtuml, and cort did not fork via github so not sure how to send a PR directly. But I've pushed to https://github.com/john-tornblom/pyxtuml/tree/ordered_by

@john-tornblom john-tornblom merged commit 5dc827b into xtuml:master Jun 15, 2018
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

Successfully merging this pull request may close these issues.

3 participants