[sqlalchemy] Querying few related tables with limiting subqueries and filtering by keyword (Pyramid and SQLAlchemy)

2014-08-27 Thread Ljós Berinn
Hi! I have defined my models in Pyramid like this: # coding: utf-8 from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Integer, Float, DateTime, ForeignKey, ForeignKeyConstraint, String, Column from sqlalchemy.orm import scoped_session, sessionmaker, relationship, back

Re: [sqlalchemy] Limiting the subquery with Pyramid/SQLAlchemy

2014-08-27 Thread Ljós Berinn
Hehe, ok I see, if it works, don't touch it =) Well, not sure if my database is happy with it, but I certainly am =) I am using sqltap for a bit of profiling, I put profiler = sqltap.start() in the beginning of my function and statistics = profiler.collect() in the end (the function is consisted

Re: [sqlalchemy] Limiting the subquery with Pyramid/SQLAlchemy

2014-08-26 Thread Ljós Berinn
Hey Jonathan! The data I need is *the most recent location* for each definition. I tried to play with Michael's query and it worked fine. I also needed to join one more table with the same principle (selecting the row only by latest timestamp) and I came up with this: sub_loc = DBSession.query

Re: [sqlalchemy] Limiting the subquery with Pyramid/SQLAlchemy

2014-08-19 Thread Ljós Berinn
ss :) On Tuesday, August 19, 2014 4:19:13 PM UTC, Michael Bayer wrote: > > > On Aug 19, 2014, at 11:12 AM, Ljós Berinn <0na...@gmail.com > > wrote: > > I have defined two models in my Pyramid app which are referencing the > existing database: > > class Locat

[sqlalchemy] Limiting the subquery with Pyramid/SQLAlchemy

2014-08-19 Thread Ljós Berinn
I have defined two models in my Pyramid app which are referencing the existing database: class Locations(Base): __tablename__ = 'Location' __table_args__ = {u'schema': 'Locations'} Unit_id = Column(ForeignKey(u'Structure.Definition.Ship_id', ondelete=u'RESTRICT', onupdate=u'CASCADE'