Hi Stephen,
Not exactly what I'm looking for (unless I misunderstand you) as I'd
like to not have the individual attributes (lower, nominal, upper) in
the class directly and carry just the _limits variable.
I have a class Result as follows:
class Result:
def __init__(self):
self._limits = (None, None, None) # (lower, nominal,
upper)
def setLimits(self, limits):
self._limits = limits
...
In the database, I have a Limits table with three columns:
lower_limit, nominal, upper_limit
I'd like to map these 3 values directly into the _limits variable:
E.g.
limits_table = Table('limits', metadata, Column('id', Integer,
primary_key = True,
metadata, Column
('lower_limit', Float),
metadata, Column('nominal',
Float),
metadata, Column
('upper_limit', Float))
mapper(Result, limits_table)
By default, the Result class will
have .id, .lower_limit, .nominal, .upper_limit created. Rather than
create the 3 attributes and map to the _limits variable as you have
suggested - is there a properties= technique in the mapper or
composite column technique (w/o modifying the Result class directly)
that supports this capability?
Thanks,
Raj
On Mar 13, 3:00 am, Stephen Emslie <[email protected]> wrote:
> You could try changing your _limit tuple to a property on the class
> that returns the tuple you want.
>
> For example:
>
> class Result(object):
>
> def get_limit(self):
> return (self.upper, self.lower, self.nominal)
> _limit = property(get_limit)
>
> Is this what you were looking for?
>
> Stephen Emslie
>
>
>
> On Wed, Mar 11, 2009 at 1:01 AM, batraone <[email protected]> wrote:
>
> > Hi,
>
> > I'm just starting to use SQLAlchemy and hit a roadblock.
>
> > I have a class Result which contains a tuple called _limits.
> > _limits = (Upper value, lower value, nominal)
>
> > I would like to map a the table's columns directly into this tuple.
>
> > From the documentation, all I can see is columns mapping directly to
> > python attributes (I.e. Result.upper_value, Result.lower_value,..).
> > Is there a way to map the three columns directly into the tuple?
>
> > I do not want to modify the Result class and therefore cannot
> > create it as composite column type.
>
> > I'm hoping there is a syntax that states "map these 3 columns" into
> > this tuple via the mapper.
>
> > Thanks,
>
> > Raj- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---