Simon, thanks for the suggestion with association proxies I used them once 
in the past.
Richard, I see your point this design might indeed have some unintended 
consequence.

As I mentioned in the first message I am aware that it's an unusual 
approach and this is a deliberate choice. I just wanted to know if it's 
possible to set up this kind of relationships using *primaryjoin* without 
having *secondary* table.

I did some digging in the source code and I think that it's not possible to 
define *MANYTOMANY* with *back_populates* without using *secondary* table, 
cause of the following:

if (
    self.direction in (ONETOMANY, MANYTOONE)
    and self.direction == other.direction
):
    raise sa_exc.ArgumentError(
        "%s and back-reference %s are "
        "both of the same direction %r.  Did you mean to "
        "set remote_side on the many-to-one side ?"
        % (other, self, self.direction)
    )



I managed to use:

companies = relationship(
    "Company",
    foreign_keys="Company.address_id",
    primaryjoin=(
        "Company.address_id == Address.address_id"
    ),
    viewonly=True
)


and:

addresses = relationship(
    "Address",
    foreign_keys="Address.address_id",
    primaryjoin=(
        "Address.address_id == Company.address_id"
    ),
    viewonly=True
)


Even with *viewonly=True* it appears that I can still mutate the 
*InstrumentedList*, but as far as I understand the changes SQLAlchemy will 
not try to persist the operations, right?
Sadly, I still don't really know the meaning of *foreign()* and *remote() *and 
how to use confidently.



-- 


*CONFIDENTIAL*


This e-mail and any attachments are confidential and 
intended solely for the addressee and may also be privileged or exempt from 
disclosure under applicable law. If you are not the addressee, or have 
received this e-mail in error, please notify the sender immediately, delete 
it from your system and do not copy, disclose or otherwise act upon any 
part of this e-mail or its attachments.

Internet communications are not 
guaranteed to be secure or virus-free. Revolut does not accept 
responsibility for any loss arising from unauthorised access to, or 
interference with, any Internet communications by any third party, or from 
the transmission of any viruses. Replies to this e-mail may be monitored by 
Revolut for operational or business reasons.

Any opinion or other 
information in this e-mail or its attachments that does not relate to the 
business of Revolut is personal to the sender and is not given or endorsed 
by Revolut. 

Registered Office: 7 Westferry Circus, Canary Wharf, London, 
England, E14 4HD. Main Office: 7 Westferry Circus, Canary Wharf, London, 
England, E14 4HD, United Kingdom. Revolut Ltd is authorised and regulated 
by the Financial Conduct Authority under the Electronic Money Regulations 
2011, Firm Reference 900562. Revolut Ltd is an Appointed Representative of 
Lending Works Ltd (for the activity of “operating an electronic system for 
lending” only).

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/fa5f20d8-65eb-47fc-b52f-712bc85a42ca%40googlegroups.com.

Reply via email to