On 06/10/2010 12:33 PM, Az wrote:
> The pprintout was:
>
> {<type 'collections.defaultdict'>: 156,
>  <type 'bool'>: 2,
>  <type 'float'>: 1,
>  <type 'int'>: 538,
>  <type 'list'>: 1130,
>  <type 'dict'>: 867,
>  <type 'NoneType'>: 1,
>  <type 'set'>: 932,
>  <type 'str'>: 577,
>  <type 'tuple'>: 1717,
>  <type 'type'>: 5,
>  <class 'sqlalchemy.util.symbol'>: 1,
>  <class 'sqlalchemy.orm.state.InstanceState'>: 236,
>  <class 'ProjectParties.Student'>: 156,
>  <class 'ProjectParties.Supervisor'>: 39,
>  <class 'ProjectParties.Project'>: 197}
>
> I think the InstanceStates come from the Supervisor and Project
> classes (197+39 = 236)
>   

Sounds right. You will need to override __deepcopy__ on those classes as
well.

>> Sounds pretty ugly. What if you add extra tables to represent runs
>> and/or trials?
>>
>> class Run(Base):
>>     # Having a separate table here gives you nice auto-incrementing run ids
>>     # and lets you attach additional information to a run, such as timestamp,
>>     # human-supplied comment, etc.
>>     __tablename__ = 'run'
>>     id = Column(Integer, primary_key=True)
>>     timestamp = Column(DateTime, nullable=False)
>>     # comment = Column(UnicodeText(100), nullable=False)
>>
>>     trials = relationship('Trial',
>>                           back_populates='run',
>>                           order_by=lambda: Trial.id.asc())
>>
>> class Trial(Base):
>>     # Having a separate table here is of dubious value, but hey it makes the
>>     # relationships a bit nicer!
>>     __tablename__ = 'trial'
>>     __table_args__ = (PrimaryKeyConstraint('run_id', 'id'), {})
>>     run_id = Column(Integer, ForeignKey('run.id'))
>>     id = Column(Integer)
>>
>>     run = relationship('Run', back_populates='trials')
>>     sim_allocs = relationship('SimAllocation', back_populates='trial')
>>
>> class SimAllocation(Base):
>>     ...
>>     __table_args__ = (PrimaryKeyConstraint('run_id', 'trial_id', 'stud_id'),
>>                       ForeignKeyConstraint(['run_id', 'trial_id'],
>>                                            ['trial.run_id', 'trial.id']),
>>                       {})
>>
>>     run_id = Column(Integer)
>>     trial_id = Column(Integer)
>>     stud_id = Column(Integer)
>>
>>     trial = relationship('Trial', back_populates='sim_allocs')
>>     
> Ah true, my solution was rather hacky and not very elegant.
>
> Your class definitions... are you defining both table and Class in one
> go? Would I have to change the way my monteCarloBasic creates
> instances of SimAllocation?
>   

I assumed you were using the declarative extension
(sqlalchemy.ext.declarative) to generate the table, class, and mapper in
one go. It's not at all necessary: you can define the tables, classes,
and mappers separately. Just use what you are most comfortable with.

-Conor

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
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.

Reply via email to