On Tuesday, December 4, 2012 5:12:51 PM UTC-3, Michael Bayer wrote:
>
>
> On Dec 4, 2012, at 2:30 PM, Diego Woitasen wrote:
>
> > Hi,
> > I have the following tables:
> >
> > rcpt_group_asoc = Table("mailing_rcptgroup_rcpts", Base.metadata,
> > Column('rcpt_id', Integer, ForeignKey('mailing_rcpt.id')),
>
> > Column('rcptgroup_id', Integer, ForeignKey('
> mailing_rcptgroup.id')))
> >
> >
> > class Rcpt(Base):
> > __tablename__ = 'mailing_rcpt'
> >
> > id = Column(Integer, primary_key=True)
> >
> > mail_addr = Column(String(128+256), nullable=False)
> > rcpt_groups = relationship("RcptGroup", secondary=rcpt_group_asoc,
> > backref="rcpts")
> >
> > class RcptGroup(Base):
> > __tablename__ = 'mailing_rcptgroup'
> >
> > id = Column(Integer, primary_key=True)
> > name = Column(String(64), nullable=False, unique=True)
> >
> > I'm trying to do:
> >
> >
> > group = db.RcptGroup.__table__
> > rcpt = db.Rcpt.__table__
> > print group.join(rcpt)
> >
> > And got:
> >
> > ArgumentError: Can't find any foreign key relationships between
> 'mailing_rcptgroup' and 'mailing_rcpt'.
>
>
> the join() method of Table (which is what RcptGroup.__table__ is) is part
> of SQLAlchemy Core and has no awareness of the relationship() construct and
> therefore no implicit awareness of the rcpt_group_assoc table, if not
> provided explicitly. If using a pure Core approach, you'd need to join
> explicitly, group.join(rcpt_group_assoc).join(rcpt).
>
> Alternatively, you can use the orm.join() construct and provide the
> relationship() bound attribute:
>
> from sqlalchemy.orm import join
>
> j = join(RcptGroup.rcpts)
>
> though typically sticking with query.join() is the simplest approach. I
> never have a need to use the standalone join() function when querying with
> the ORM.
>
>
>
>
>
Thanks.
I'm mixing ORM and Core in my app because I performance in critical in some
parts of the code. Are there other problems related to this mix?
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/rysk8L4nrRcJ.
To post to this group, send email to [email protected].
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.