Skip to content

server side defaults and composites #2309

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Michael Bayer (@zzzeek)

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base= declarative_base()


class MyComposite(object):
    def __init__(self, datax, datay):
        self.datax = datax
        self.datay = datay
    def __composite_values__(self):
        return self.datax, self.datay

class A(Base):
    __tablename__ = "a"

    id = Column(Integer, primary_key=True)
    x = Column(Integer, server_default="9")
    y = Column(Integer, default=10)
    value = composite(MyComposite, x, y)

e = create_engine('sqlite://', echo=True)
Base.metadata.create_all(e)
s = Session(e)
a1 = A(value=MyComposite(None, None))
s.add(a1)
s.flush()

assert a1.value.datay == 10
assert a1.value.datax == 9

the fix for #2308 will also get this one

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Oct 26, 2011

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

d9adb2a

sqlalchemy-bot

sqlalchemy-bot commented on Oct 26, 2011

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
added this to the 0.7.4 milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingorm

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          server side defaults and composites · Issue #2309 · sqlalchemy/sqlalchemy