allen.fowler wrote:
>   
>> ...> To clarify:
>>
>>     
>>> I am using SQLAlchemy's Declarative Base to fully define and create my
>>> database.
>>>       
>>> For instance, there is a simple class/table Records, and I would like
>>> to define a class CurrentRecords that is implemented in the database
>>> as a view on Records.
>>>       
>>> In this way, I can avoid polluting my application code with filtering
>>> out all the non-active records every time I want to query Records.
>>>       
>> Just define CurrentRecords as a table, i.e. in my app one of my views is:
>>
>> class Vconsumption(Base):
>>     __table__ = sa.Table(u'vconsumption', metadata,
>>     sa.Column(u'consumptionid', sa.Integer(),
>> sa.ForeignKey(u'consumption.consumptionid'), primary_key=True),
>> ...
>>     )
>>
>>     consumption = sao.relation(Consumption)
>>
>> And I relate it back to the real consumption table, but never
>> write/flush the view and do have to have a unique key which you define
>> as "primary key" to SA.
>>
>> Werner
>>     
>
> What functional gain does this approuch provide over just querying the
> Consumption table?  I am not clear on how you are using this....  can
> you clarify?
>   
As you can see from the view definition (below) it just contains id's 
from four tables plus a description which comes from one of two tables, 
but in the application I sometimes need more details from the actual 
consumption details, therefore the relation.
> As an aside, I wonder if it is possible to just subclass my Records
> object so that the CurrentRecords class adds/enforces certain
> filter_by parameters for any query against it.
>   
Do not know the answer to this, nor do I have a guess :-) .

Werner

Partial view definition:
CREATE VIEW VCONSUMPTION(
    CONSUMPTIONID,
    FK_CBBOTTLEID,
    DESCRIPTION,
    FK_CONSEVENTID,
    FK_CONSBATCHID)
AS
select con.consumptionid,
       con.fk_cbbottleid,
       coalesce(cb.description, ce.description),
       ce.conseventid,
       cb.consbatchid
etc
> Thank you.  :)
>
>
>
> >
>
>   




--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to