Thank you for the quick reply.

> shouldn't this be as simple as "sample.container = container"

Yeah... I thought so too... And actually, the getter/setters (the
synonym or property) just do that... (and a check for the parameter
type):

class Sample(declarativeBase):
       # yadda, yadda, yadda ...
       def setContainer(self, container):
              if isinstance(container, Container):
                     self._container = container
              else:
                     raise TypeError("received a %s when expecting a
Container" % type(container))

Anyway... if my idea is not wrong, I'll check if the error is
somewhere else. It's good to know that I'm going in the right
direction!

Thank you!

2011/1/21 A.M. <age...@themactionfaction.com>:
>
> On Jan 21, 2011, at 12:29 PM, Hector Blanco wrote:
>
>> Hello list!
>>
>> I have a couple of classes. One of the behaves as the container of the other:
>>
>> class ContainerOfSamples(declarativeBase):
>>       __tablename__ = "containers"
>>
>>       _id = Column("id", Integer, primary_key=True)
>>       _samples = relationship("Samples", cascade="all, delete", 
>> collection_class=set)
>>
>>       def setSamples(self, samples):
>>               self._samples = samples
>>
>>       def getSamples(self):
>>               return self._samples
>>
>>       def addSample(self, sample):
>>               self._samples.add(sample)
>>
>>       id = sqlalchemy.orm.synonym('_id', descriptor=property(getId, setId))
>>       samples = sqlalchemy.orm.synonym('_samples',
>>                                       descriptor=property(getSamples, 
>> setSamples))
>>
>>
>> class Sample(declarativeBase):
>>       __tablename__ = "containers"
>>
>>       _id = Column("id", Integer, primary_key=True)
>>       _whatever = Column("whatever", String(20))
>>       _containerId = Column("container_id", Integer, 
>> ForeignKey("containers.id"))
>>       _container = relationship("Container", uselist=False)
>>
>>       def __hash__(self):
>>               return int(self.id)
>>
>>       def setContainer(self, container):
>>               self._container = container
>>
>>       def getContainer(self):
>>               return self._container
>>
>>       id = sqlalchemy.orm.synonym('_id', descriptor=property(getId, setId))
>>       whatever = sqlalchemy.orm.synonym('_whatever',
>>                                       descriptor=property(getWhatever, 
>> setWhatever))
>>       container = sqlalchemy.orm.synonym('_container',
>>                                       descriptor=property(getContainer, 
>> setContainer))
>>
>>
>> sample = Sample()
>> container = ContainerOfSamples()
>> sample.container(container)
>
> I don't understand the need for the synonyms, but shouldn't this be as simple 
> as "sample.container = container"? The relationship on sample is already 
> defined... maybe you are confused because you think you need these getters 
> and setters- in the above example, I don't see any need for them.
>
> Cheers,
> M
>
> --
> 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.
>
>

-- 
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