On Aug 22, 2007, at 11:37 AM, Jian Luo wrote:

>
> Hi List,
>
> I have a table defined in elixir, simplified as following:
> class Widget(Entity):
>     """Form, Fieldset or Field
>     """
>     has_field('name', Unicode(40), nullable=False, unique=True)
>     has_and_belongs_to_many('children', of_kind='Widget',
> inverse='parents')
>     has_and_belongs_to_many('parents', of_kind='Widget',
> inverse='children')
>

im not sure about how elixir does bi-directional relationships but it  
seems strange that you have set up the "children" and "parents"  
relationships twice in both directions.    but this might be elixir's  
"strangeness".

> when i explicitly do join on that table like this:
>>>> widgets = Widget.q.filter_by(id=1).join('children',  
>>>> aliased=True).all()

While the results you're getting below arent right, I would also  
point out that the above query doesnt actually gain anything by  
having the join to "children" since those rows arent being filtered  
or fetched...unless  you're just illustrating for the sake of example.

>
> then I got:
> DBAPIError: (ProgrammingError) missing FROM-clause entry for table
> "widget_2"
> LINE 2: ...ON widget_parents__widget_children_1.widget_id2 =
> widget_2.i...
>
> 'SELECT widget.name AS widget_name, widget.id AS widget_id,\n
> FROM widget LEFT OUTER JOIN widget_parents__widget_children AS
> widget_parents__widget_children_1 ON
> widget_parents__widget_children_1.widget_id2 = widget_2.id LEFT OUTER
> JOIN widget AS widget_2 ON
> widget_parents__widget_children_1.widget_id1 = widget_2.id\n
> WHERE widget.id = %(widget_id)s' {'widget_id': 1}
>
> It seems like the aliases are wrong.
> and the PropertyAliasedClauses is to be blamed.
>
> Is this a bug? or I didn't join things in the right way?

 From a SQLAlchemy mapper perspective, since you are doing a many-to- 
many relation from one table to itself, you definitely need to setup  
the "primaryjoin" and "secondaryjoin" attributes on this relation so  
SQLAlchemy knows how the table should be connected to the association  
table on both directions.  I think that should alleviate your issue.

Hope this helps.

- mike



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to