- attached activemapper.py.patch
ActiveMapper for arbitary selects
I've created a patch which allows arbitary selects or existing Table instances to be used with ActiveMapper.
This can be done by giving an Alias or a Table in place of a table name.
class mapping:
__table__ = select(...).alias('...')
I've also added three mapper options __primary_key__
, __order_by__
and __extension__
.
__primary_key__
and __order_by__
work like the order_by option of an ActiveMapper relationship.
They can receive a string or a list of strings.
These strings will be replaced by the respective columns of the Table or Alias.
During the change, I slightly refactored the existing code in order to reduce the amount of code to be added.
The new module passed all existing unit tests.
If you agree with the proposed enhancement in general, let me know if you want me to change something in particular.
Martin
Comments (9)
-
Account Deleted -
Account Deleted The patch is larger than expected because I removed all trailing whitespaces.
-
repo owner hi -
this is a very large change to ActiveMapper, which I've no problem patching in except the primary maintainers of ActiveMapper have moved on to the SQLElixir project which is meant to replace ActiveMapper. might you be better off proposing your changes on that project ?
in the case here, I dont have the resources to test these changes myself.
-
Account Deleted Hi Mike,
I know that Jonathan has dropped ActiveMapper in favor of Elixir. I wasn't sure whether ActiveMapper will remain an SQLAlchemy extension for backward compatibility.
As far as I can see, Elixir has been created from scratch and has not much in common with ActiveMapper. So, I don't think my changes make much sense there.
I've created this patch for personal use in order to overcome some of the restrictions of ActiveMapper. Once it worked, I thought I could share the result with others. I use the patched version with two different models. So I'm pretty sure it works ;-) Nevertheless, I understand your point.
Thanks, Martin
-
repo owner - changed status to wontfix
the patch doesnt apply to the current 0.4 activemapper; if the patch can be improved and maybe some unit tests added, i can patch it. the ticket can be reopened with a new patch.
-
Account Deleted - attached activemapper.py.2.patch
lib/sqlalchemy/ext/activemapper.py.patch
-
Account Deleted - attached activemapper.py.3.patch
test/ext/activemapper.py.patch
-
Account Deleted - removed status
- changed status to open
I've modified the patch so that it's compatible with SA 0.4.
There're still deprecation warnings. I couldn't figure out how to get rid of them without breaking existing code.
Since the try/except block at the beginning of the file always throws an AttributeError with SA 0.4, I removed the try block and left only the except block.
The second patch adds unittests for the new functionality introduced by the first patch. It also modifies existing tests slightly in order to get rid of deprecation warnings.
Martin
-
repo owner - changed status to wontfix
- Log in to comment
Proposed patch