I have tried this, but still cannot get it figured out. I keep getting
exceptions such as " Could not determine join condition between
parent/child tables on relationship...", etc. There are two things that
seems to be hindering me:
- I'm using classical mappings. Many resources online assume declarative
style, and I'm having trouble converting it. The use of classical mapping
is due to how the project was started and is the convention used. To move
to declarative style would be a rather large undertaking, though I guess
it's possible.
- I'm using a self-referential mapping, which also complicates things,
since most resources I find have two distinct objects along with the
association.
On Monday, July 6, 2015 at 1:14:29 PM UTC-4, Michael Bayer wrote:
>
>
>
> On 7/6/15 12:06 PM, Ryan Holmes wrote:
>
> I have an interesting problem that I haven't been able to solve for
> quite some time. I keep finding information about association proxies and
> the like, but nothing that really helps (or maybe I'm implementing it
> incorrectly).
>
> Let's start with this:
>
> class HandledProjectedItemList(list):
> def append(self, proj):
> proj.projected = True
> list.append(self, proj)
>
>
> item_table = Table("items", saveddata_meta,
> Column("ID", Integer, primary_key = True),
> Column("itemID", Integer, nullable = False, index = True),
> Column("name", String, nullable = False),
> Column("timestamp", Integer, nullable = False),
> )
>
> projectedItem_table = Table("projectedItem", saveddata_meta,
> Column("sourceID", ForeignKey("item.ID"), primary_key = True),
> Column("destID", ForeignKey("item.ID"), primary_key = True),
> Column("enabled", Integer))
>
> mapper(Item, item_table,
> properties = {"projectedItem" : relation(Item,
> primaryjoin = projectedItem_table.c.destID ==
> item_table.c.ID,
> secondaryjoin = item_table.c.ID ==
> projectedItem_table.c.sourceID,
> secondary = projectedItem_table,
> collection_class = HandledProjectedItemList)
> })
>
>
> I have two tables: a `item` table, and a `projectedItem` table. The
> `item` table is the main one, and contains information on items. The
> projected items table is a self-referential many-to-many relationship to
> the items table, where each item may have a collection of other items
> attached to it. We use a custom collection class to load this relationship
> so that we can modify a special attribute in the Item objects (if they are
> loaded via this relationship, they have their `projected` attribute set to
> `True`).
>
> This works great. But I also want read / write access to that extra
> `enabled` column in the relationship table, while maintaining the current
> functionality of loading the projected items into this custom collection
> class. I haven't found any information on that that helps, or like I said
> before, maybe I'm just not using it correctly.
>
> you would make a new class ProjectedItem and map it to the
> projectedItem_table. This is the association object pattern (get that to
> work first, without the "proxy" part), illustrated at
> http://docs.sqlalchemy.org/en/rel_1_0/orm/basic_relationships.html#association-object.
>
> Once that works, and all that's left is the inconvenience of navigating
> from Item->projecteditems->item, then you can apply the association proxy
> pattern to convert those two hops into just one (
> http://docs.sqlalchemy.org/en/rel_1_0/orm/extensions/associationproxy.html
> ).
>
>
>
> --
> 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 [email protected] <javascript:>.
> To post to this group, send email to [email protected]
> <javascript:>.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
>
>
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.