Ticket #108 (accepted defect)

Opened 3 years ago

Last modified 3 years ago

order_by in OneToMany fails if colname is specified on target field

Reported by: guest Owned by: ged
Priority: normal Milestone:
Component: core Version: 0.7.1
Keywords: Cc:

Description

By my reading of the OneToMany docs, the order_by parameter refers to the Field in the target class used to order the results of this collection. "order_by: Specify which field(s) should be used to sort the results given by accessing the relation field."

However, when attempting to implement this behavior, I found that specifying the field name results in an Exception, "no column found", during setup of the Entities. A runnable failing example is attached. The traceback it outputs follows this report.

I suspect that either the order_by parameter should accept field names or the documentation should be updated to reflect that column names must be specified (certainly less desirable).

python .\elixir_order_by.py

Traceback (most recent call last):

File ".\elixir_order_by.py", line 21, in

<module>

setup_all(True)

File "C:\Python\lib\site-packages\elixir-0.7.1-py2.6.egg\elixir\init.py",

line 94, in setup_all

setup_entities(entities)

File "C:\Python\lib\site-packages\elixir-0.7.1-py2.6.egg\elixir\entity.py", line 951, in setup_entities

method()

File "C:\Python\lib\site-packages\elixir-0.7.1-py2.6.egg\elixir\entity.py", line 469, in setup_properties

self.call_builders('create_properties')

File "C:\Python\lib\site-packages\elixir-0.7.1-py2.6.egg\elixir\entity.py", line 481, in call_builders

getattr(builder, what)()

File "C:\Python\lib\site-packages\elixir-0.7.1-py2.6.egg\elixir\relationships.py", line 466, in create_properties

self.target._descriptor.translate_order_by(kwargsorder_by?)

File "C:\Python\lib\site-packages\elixir-0.7.1-py2.6.egg\elixir\entity.py", line 373, in translate_order_by

col = self.get_column(colname.strip('-'))

File "C:\Python\lib\site-packages\elixir-0.7.1-py2.6.egg\elixir\entity.py", line 558, in get_column

% (key, self.entity.name))

Exception: No column named 'position' found in the table of the 'Bullet' entity!

Attachments

elixir_order_by.py (0.9 kB) - added by guest 3 years ago.

Change History

Changed 3 years ago by guest

Changed 3 years ago by guest

I tracked the origin of the problem to relationships.py:460 - where the Relationships depend on the EntityDescriptor to locate the appropriate columns, and the EntityDescriptor is not aware of any Fields until the mapper is created.

Perhaps it's not possible for order_by to accept field names, and must always specify column names.

Changed 3 years ago by ged

  • owner set to ged
  • status changed from new to accepted
  • milestone set to 0.8

Your use case makes more sense than the current behavior which, as you found out, is to use column names, not property names. I'll see what I can do to change that. Sorry it took me so long to react, I was busy with other stuff.

Changed 3 years ago by ged

  • milestone deleted

Well, this will need some pretty heavy refactoring...

Note: See TracTickets for help on using tickets.