<s> from sqlalchemy . testing import eq_ <EOL> from sqlalchemy import * <EOL> from sqlalchemy . orm import * <EOL> from sqlalchemy import testing <EOL> from test . orm import _fixtures <EOL> from sqlalchemy . testing import fixtures , AssertsCompiledSQL <EOL> from sqlalchemy . testing . schema import Table , Column <EOL> class SingleInheritanceTest ( testing . AssertsCompiledSQL , fixtures . MappedTest ) : <EOL> __dialect__ = '<STR_LIT:default>' <EOL> @ classmethod <EOL> def define_tables ( cls , metadata ) : <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True , test_needs_autoincrement = True ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT:50> ) ) , <EOL> Column ( '<STR_LIT>' , String ( <NUM_LIT:50> ) ) , <EOL> Column ( '<STR_LIT>' , String ( <NUM_LIT:50> ) ) , <EOL> Column ( '<STR_LIT:type>' , String ( <NUM_LIT:20> ) ) ) <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True , test_needs_autoincrement = True ) , <EOL> Column ( '<STR_LIT>' , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT:50> ) ) , <EOL> ) <EOL> @ classmethod <EOL> def setup_classes ( cls ) : <EOL> global Employee , Manager , Engineer , JuniorEngineer <EOL> class Employee ( cls . Comparable ) : <EOL> pass <EOL> class Manager ( Employee ) : <EOL> pass <EOL> class Engineer ( Employee ) : <EOL> pass <EOL> class JuniorEngineer ( Engineer ) : <EOL> pass <EOL> @ classmethod <EOL> def setup_mappers ( cls ) : <EOL> Employee , Manager , JuniorEngineer , employees , Engineer = ( cls . classes . Employee , <EOL> cls . classes . Manager , <EOL> cls . classes . JuniorEngineer , <EOL> cls . tables . employees , <EOL> cls . classes . Engineer ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type ) <EOL> mapper ( Manager , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( JuniorEngineer , inherits = Engineer , polymorphic_identity = '<STR_LIT>' ) <EOL> def test_single_inheritance ( self ) : <EOL> Employee , JuniorEngineer , Manager , Engineer = ( self . classes . Employee , <EOL> self . classes . JuniorEngineer , <EOL> self . classes . Manager , <EOL> self . classes . Engineer ) <EOL> session = create_session ( ) <EOL> m1 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> e1 = Engineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' ) <EOL> e2 = JuniorEngineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' ) <EOL> session . add_all ( [ m1 , e1 , e2 ] ) <EOL> session . flush ( ) <EOL> assert session . query ( Employee ) . all ( ) == [ m1 , e1 , e2 ] <EOL> assert session . query ( Engineer ) . all ( ) == [ e1 , e2 ] <EOL> assert session . query ( Manager ) . all ( ) == [ m1 ] <EOL> assert session . query ( JuniorEngineer ) . all ( ) == [ e2 ] <EOL> m1 = session . query ( Manager ) . one ( ) <EOL> session . expire ( m1 , [ '<STR_LIT>' ] ) <EOL> eq_ ( m1 . manager_data , "<STR_LIT>" ) <EOL> row = session . query ( Engineer . name , Engineer . employee_id ) . filter ( Engineer . name == '<STR_LIT>' ) . first ( ) <EOL> assert row . name == '<STR_LIT>' <EOL> assert row . employee_id == e1 . employee_id <EOL> def test_multi_qualification ( self ) : <EOL> JuniorEngineer , Manager , Engineer = ( self . classes . JuniorEngineer , <EOL> self . classes . Manager , <EOL> self . classes . Engineer ) <EOL> session = create_session ( ) <EOL> m1 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> e1 = Engineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' ) <EOL> e2 = JuniorEngineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' ) <EOL> session . add_all ( [ m1 , e1 , e2 ] ) <EOL> session . flush ( ) <EOL> ealias = aliased ( Engineer ) <EOL> eq_ ( <EOL> session . query ( Manager , ealias ) . all ( ) , <EOL> [ ( m1 , e1 ) , ( m1 , e2 ) ] <EOL> ) <EOL> eq_ ( <EOL> session . query ( Manager . name ) . all ( ) , <EOL> [ ( "<STR_LIT>" , ) ] <EOL> ) <EOL> eq_ ( <EOL> session . query ( Manager . name , ealias . name ) . all ( ) , <EOL> [ ( "<STR_LIT>" , "<STR_LIT>" ) , ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> ) <EOL> eq_ ( <EOL> session . query ( func . upper ( Manager . name ) , func . upper ( ealias . name ) ) . all ( ) , <EOL> [ ( "<STR_LIT>" , "<STR_LIT>" ) , ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> ) <EOL> eq_ ( <EOL> session . query ( Manager ) . add_entity ( ealias ) . all ( ) , <EOL> [ ( m1 , e1 ) , ( m1 , e2 ) ] <EOL> ) <EOL> eq_ ( <EOL> session . query ( Manager . name ) . add_column ( ealias . name ) . all ( ) , <EOL> [ ( "<STR_LIT>" , "<STR_LIT>" ) , ( "<STR_LIT>" , "<STR_LIT>" ) ] <EOL> ) <EOL> def test_from_self ( self ) : <EOL> Engineer = self . classes . Engineer <EOL> sess = create_session ( ) <EOL> self . assert_compile ( sess . query ( Engineer ) . from_self ( ) , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> use_default_dialect = True ) <EOL> def test_from_self_count ( self ) : <EOL> Engineer = self . classes . Engineer <EOL> sess = create_session ( ) <EOL> col = func . count ( literal_column ( '<STR_LIT:*>' ) ) <EOL> self . assert_compile ( <EOL> sess . query ( Engineer . employee_id ) . from_self ( col ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> use_default_dialect = True <EOL> ) <EOL> def test_select_from ( self ) : <EOL> Manager , JuniorEngineer , employees , Engineer = ( self . classes . Manager , <EOL> self . classes . JuniorEngineer , <EOL> self . tables . employees , <EOL> self . classes . Engineer ) <EOL> sess = create_session ( ) <EOL> m1 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> m2 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> e1 = Engineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' ) <EOL> e2 = JuniorEngineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' ) <EOL> sess . add_all ( [ m1 , m2 , e1 , e2 ] ) <EOL> sess . flush ( ) <EOL> eq_ ( <EOL> sess . query ( Manager ) . select_from ( employees . select ( ) . limit ( <NUM_LIT:10> ) ) . all ( ) , <EOL> [ m1 , m2 ] <EOL> ) <EOL> def test_count ( self ) : <EOL> Employee , JuniorEngineer , Manager , Engineer = ( self . classes . Employee , <EOL> self . classes . JuniorEngineer , <EOL> self . classes . Manager , <EOL> self . classes . Engineer ) <EOL> sess = create_session ( ) <EOL> m1 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> m2 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> e1 = Engineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' ) <EOL> e2 = JuniorEngineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' ) <EOL> sess . add_all ( [ m1 , m2 , e1 , e2 ] ) <EOL> sess . flush ( ) <EOL> eq_ ( sess . query ( Manager ) . count ( ) , <NUM_LIT:2> ) <EOL> eq_ ( sess . query ( Engineer ) . count ( ) , <NUM_LIT:2> ) <EOL> eq_ ( sess . query ( Employee ) . count ( ) , <NUM_LIT:4> ) <EOL> eq_ ( sess . query ( Manager ) . filter ( Manager . name . like ( '<STR_LIT>' ) ) . count ( ) , <NUM_LIT:2> ) <EOL> eq_ ( sess . query ( Employee ) . filter ( Employee . name . like ( '<STR_LIT>' ) ) . count ( ) , <NUM_LIT:3> ) <EOL> def test_exists_standalone ( self ) : <EOL> Engineer = self . classes . Engineer <EOL> sess = create_session ( ) <EOL> self . assert_compile ( <EOL> sess . query ( <EOL> sess . query ( Engineer ) . filter ( Engineer . name == '<STR_LIT:foo>' ) . exists ( ) ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_type_filtering ( self ) : <EOL> Employee , Manager , reports , Engineer = ( self . classes . Employee , <EOL> self . classes . Manager , <EOL> self . tables . reports , <EOL> self . classes . Engineer ) <EOL> class Report ( fixtures . ComparableEntity ) : <EOL> pass <EOL> mapper ( Report , reports , properties = { <EOL> '<STR_LIT>' : relationship ( Employee , backref = '<STR_LIT>' ) } ) <EOL> sess = create_session ( ) <EOL> m1 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> r1 = Report ( employee = m1 ) <EOL> sess . add_all ( [ m1 , r1 ] ) <EOL> sess . flush ( ) <EOL> rq = sess . query ( Report ) <EOL> assert len ( rq . filter ( Report . employee . of_type ( Manager ) . has ( ) ) . all ( ) ) == <NUM_LIT:1> <EOL> assert len ( rq . filter ( Report . employee . of_type ( Engineer ) . has ( ) ) . all ( ) ) == <NUM_LIT:0> <EOL> def test_type_joins ( self ) : <EOL> Employee , Manager , reports , Engineer = ( self . classes . Employee , <EOL> self . classes . Manager , <EOL> self . tables . reports , <EOL> self . classes . Engineer ) <EOL> class Report ( fixtures . ComparableEntity ) : <EOL> pass <EOL> mapper ( Report , reports , properties = { <EOL> '<STR_LIT>' : relationship ( Employee , backref = '<STR_LIT>' ) } ) <EOL> sess = create_session ( ) <EOL> m1 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> r1 = Report ( employee = m1 ) <EOL> sess . add_all ( [ m1 , r1 ] ) <EOL> sess . flush ( ) <EOL> rq = sess . query ( Report ) <EOL> assert len ( rq . join ( Report . employee . of_type ( Manager ) ) . all ( ) ) == <NUM_LIT:1> <EOL> assert len ( rq . join ( Report . employee . of_type ( Engineer ) ) . all ( ) ) == <NUM_LIT:0> <EOL> class RelationshipFromSingleTest ( testing . AssertsCompiledSQL , fixtures . MappedTest ) : <EOL> @ classmethod <EOL> def define_tables ( cls , metadata ) : <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True , test_needs_autoincrement = True ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT:50> ) ) , <EOL> Column ( '<STR_LIT:type>' , String ( <NUM_LIT:20> ) ) , <EOL> ) <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True , test_needs_autoincrement = True ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT:50> ) ) , <EOL> ) <EOL> @ classmethod <EOL> def setup_classes ( cls ) : <EOL> class Employee ( cls . Comparable ) : <EOL> pass <EOL> class Manager ( Employee ) : <EOL> pass <EOL> class Stuff ( cls . Comparable ) : <EOL> pass <EOL> def test_subquery_load ( self ) : <EOL> employee , employee_stuff , Employee , Stuff , Manager = ( self . tables . employee , <EOL> self . tables . employee_stuff , <EOL> self . classes . Employee , <EOL> self . classes . Stuff , <EOL> self . classes . Manager ) <EOL> mapper ( Employee , employee , polymorphic_on = employee . c . type , polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( Manager , inherits = Employee , polymorphic_identity = '<STR_LIT>' , properties = { <EOL> '<STR_LIT>' : relationship ( Stuff ) <EOL> } ) <EOL> mapper ( Stuff , employee_stuff ) <EOL> sess = create_session ( ) <EOL> context = sess . query ( Manager ) . options ( subqueryload ( '<STR_LIT>' ) ) . _compile_context ( ) <EOL> subq = context . attributes [ ( '<STR_LIT>' , <EOL> ( class_mapper ( Manager ) , class_mapper ( Manager ) . attrs . stuff ) ) ] <EOL> self . assert_compile ( subq , <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> use_default_dialect = True <EOL> ) <EOL> class RelationshipToSingleTest ( testing . AssertsCompiledSQL , fixtures . MappedTest ) : <EOL> __dialect__ = '<STR_LIT:default>' <EOL> @ classmethod <EOL> def define_tables ( cls , metadata ) : <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True , test_needs_autoincrement = True ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT:50> ) ) , <EOL> Column ( '<STR_LIT>' , String ( <NUM_LIT:50> ) ) , <EOL> Column ( '<STR_LIT>' , String ( <NUM_LIT:50> ) ) , <EOL> Column ( '<STR_LIT:type>' , String ( <NUM_LIT:20> ) ) , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) ) <EOL> ) <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True , test_needs_autoincrement = True ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT:50> ) ) , <EOL> ) <EOL> @ classmethod <EOL> def setup_classes ( cls ) : <EOL> class Company ( cls . Comparable ) : <EOL> pass <EOL> class Employee ( cls . Comparable ) : <EOL> pass <EOL> class Manager ( Employee ) : <EOL> pass <EOL> class Engineer ( Employee ) : <EOL> pass <EOL> class JuniorEngineer ( Engineer ) : <EOL> pass <EOL> def test_of_type ( self ) : <EOL> JuniorEngineer , Company , companies , Manager , Employee , employees , Engineer = ( self . classes . JuniorEngineer , <EOL> self . classes . Company , <EOL> self . tables . companies , <EOL> self . classes . Manager , <EOL> self . classes . Employee , <EOL> self . tables . employees , <EOL> self . classes . Engineer ) <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Employee , backref = '<STR_LIT>' ) <EOL> } ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type ) <EOL> mapper ( Manager , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( JuniorEngineer , inherits = Engineer , polymorphic_identity = '<STR_LIT>' ) <EOL> sess = sessionmaker ( ) ( ) <EOL> c1 = Company ( name = '<STR_LIT>' ) <EOL> c2 = Company ( name = '<STR_LIT>' ) <EOL> m1 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' , company = c1 ) <EOL> m2 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' , company = c2 ) <EOL> e1 = Engineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' , company = c2 ) <EOL> e2 = JuniorEngineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' , company = c1 ) <EOL> sess . add_all ( [ c1 , c2 , m1 , m2 , e1 , e2 ] ) <EOL> sess . commit ( ) <EOL> sess . expunge_all ( ) <EOL> eq_ ( <EOL> sess . query ( Company ) . filter ( Company . employees . of_type ( JuniorEngineer ) . any ( ) ) . all ( ) , <EOL> [ <EOL> Company ( name = '<STR_LIT>' ) , <EOL> ] <EOL> ) <EOL> eq_ ( <EOL> sess . query ( Company ) . join ( Company . employees . of_type ( JuniorEngineer ) ) . all ( ) , <EOL> [ <EOL> Company ( name = '<STR_LIT>' ) , <EOL> ] <EOL> ) <EOL> def test_of_type_aliased_fromjoinpoint ( self ) : <EOL> Company , Employee , Engineer = self . classes . Company , self . classes . Employee , self . classes . Engineer <EOL> companies , employees = self . tables . companies , self . tables . employees <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Employee ) <EOL> } ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> sess = create_session ( ) <EOL> self . assert_compile ( <EOL> sess . query ( Company ) . outerjoin ( <EOL> Company . employee . of_type ( Engineer ) , <EOL> aliased = True , from_joinpoint = True ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_join_explicit_onclause_no_discriminator ( self ) : <EOL> Company , Employee , Engineer = ( <EOL> self . classes . Company , <EOL> self . classes . Employee , <EOL> self . classes . Engineer ) <EOL> companies , employees = self . tables . companies , self . tables . employees <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Employee ) <EOL> } ) <EOL> mapper ( Employee , employees ) <EOL> mapper ( Engineer , inherits = Employee ) <EOL> sess = create_session ( ) <EOL> self . assert_compile ( <EOL> sess . query ( Company , Engineer . name ) . join ( <EOL> Engineer , Company . company_id == Engineer . company_id ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_outer_join_prop ( self ) : <EOL> Company , Employee , Engineer = self . classes . Company , self . classes . Employee , self . classes . Engineer <EOL> companies , employees = self . tables . companies , self . tables . employees <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Engineer ) <EOL> } ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> sess = create_session ( ) <EOL> self . assert_compile ( <EOL> sess . query ( Company , Engineer . name ) . outerjoin ( "<STR_LIT>" ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_outer_join_prop_alias ( self ) : <EOL> Company , Employee , Engineer = self . classes . Company , self . classes . Employee , self . classes . Engineer <EOL> companies , employees = self . tables . companies , self . tables . employees <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Engineer ) <EOL> } ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> eng_alias = aliased ( Engineer ) <EOL> sess = create_session ( ) <EOL> self . assert_compile ( <EOL> sess . query ( Company , eng_alias . name ) . outerjoin ( eng_alias , Company . engineers ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_outer_join_literal_onclause ( self ) : <EOL> Company , Employee , Engineer = self . classes . Company , self . classes . Employee , self . classes . Engineer <EOL> companies , employees = self . tables . companies , self . tables . employees <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Engineer ) <EOL> } ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> sess = create_session ( ) <EOL> self . assert_compile ( <EOL> sess . query ( Company , Engineer ) . outerjoin ( <EOL> Engineer , Company . company_id == Engineer . company_id ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_outer_join_literal_onclause_alias ( self ) : <EOL> Company , Employee , Engineer = self . classes . Company , self . classes . Employee , self . classes . Engineer <EOL> companies , employees = self . tables . companies , self . tables . employees <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Engineer ) <EOL> } ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> eng_alias = aliased ( Engineer ) <EOL> sess = create_session ( ) <EOL> self . assert_compile ( <EOL> sess . query ( Company , eng_alias ) . outerjoin ( <EOL> eng_alias , Company . company_id == eng_alias . company_id ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_outer_join_no_onclause ( self ) : <EOL> Company , Employee , Engineer = self . classes . Company , self . classes . Employee , self . classes . Engineer <EOL> companies , employees = self . tables . companies , self . tables . employees <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Engineer ) <EOL> } ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> sess = create_session ( ) <EOL> self . assert_compile ( <EOL> sess . query ( Company , Engineer ) . outerjoin ( <EOL> Engineer ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_outer_join_no_onclause_alias ( self ) : <EOL> Company , Employee , Engineer = self . classes . Company , self . classes . Employee , self . classes . Engineer <EOL> companies , employees = self . tables . companies , self . tables . employees <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Engineer ) <EOL> } ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> eng_alias = aliased ( Engineer ) <EOL> sess = create_session ( ) <EOL> self . assert_compile ( <EOL> sess . query ( Company , eng_alias ) . outerjoin ( <EOL> eng_alias ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_no_aliasing_from_overlap ( self ) : <EOL> Company , Employee , Engineer , Manager = self . classes . Company , self . classes . Employee , self . classes . Engineer , self . classes . Manager <EOL> companies , employees = self . tables . companies , self . tables . employees <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Employee , backref = "<STR_LIT>" ) <EOL> } ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( Manager , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> s = create_session ( ) <EOL> q1 = s . query ( Engineer ) . join ( Engineer . company ) . join ( Manager , Company . employees ) <EOL> q2 = s . query ( Engineer ) . join ( Engineer . company ) . join ( Manager , Company . company_id == Manager . company_id ) <EOL> q3 = s . query ( Engineer ) . join ( Engineer . company ) . join ( Manager , Company . employees . of_type ( Manager ) ) <EOL> q4 = s . query ( Engineer ) . join ( Company , Company . company_id == Engineer . company_id ) . join ( Manager , Company . employees . of_type ( Manager ) ) <EOL> q5 = s . query ( Engineer ) . join ( Company , Company . company_id == Engineer . company_id ) . join ( Manager , Company . company_id == Manager . company_id ) <EOL> for q in [ q1 , q2 , q3 , q4 , q5 ] : <EOL> self . assert_compile ( <EOL> q , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_relationship_to_subclass ( self ) : <EOL> JuniorEngineer , Company , companies , Manager , Employee , employees , Engineer = ( self . classes . JuniorEngineer , <EOL> self . classes . Company , <EOL> self . tables . companies , <EOL> self . classes . Manager , <EOL> self . classes . Employee , <EOL> self . tables . employees , <EOL> self . classes . Engineer ) <EOL> mapper ( Company , companies , properties = { <EOL> '<STR_LIT>' : relationship ( Engineer ) <EOL> } ) <EOL> mapper ( Employee , employees , polymorphic_on = employees . c . type , properties = { <EOL> '<STR_LIT>' : relationship ( Company ) <EOL> } ) <EOL> mapper ( Manager , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( Engineer , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( JuniorEngineer , inherits = Engineer , polymorphic_identity = '<STR_LIT>' ) <EOL> sess = sessionmaker ( ) ( ) <EOL> c1 = Company ( name = '<STR_LIT>' ) <EOL> c2 = Company ( name = '<STR_LIT>' ) <EOL> m1 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' , company = c1 ) <EOL> m2 = Manager ( name = '<STR_LIT>' , manager_data = '<STR_LIT>' , company = c2 ) <EOL> e1 = Engineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' , company = c2 ) <EOL> e2 = JuniorEngineer ( name = '<STR_LIT>' , engineer_info = '<STR_LIT>' , company = c1 ) <EOL> sess . add_all ( [ c1 , c2 , m1 , m2 , e1 , e2 ] ) <EOL> sess . commit ( ) <EOL> eq_ ( c1 . engineers , [ e2 ] ) <EOL> eq_ ( c2 . engineers , [ e1 ] ) <EOL> sess . expunge_all ( ) <EOL> eq_ ( sess . query ( Company ) . order_by ( Company . name ) . all ( ) , <EOL> [ <EOL> Company ( name = '<STR_LIT>' , engineers = [ JuniorEngineer ( name = '<STR_LIT>' ) ] ) , <EOL> Company ( name = '<STR_LIT>' , engineers = [ Engineer ( name = '<STR_LIT>' ) ] ) <EOL> ] <EOL> ) <EOL> sess . expunge_all ( ) <EOL> eq_ ( sess . query ( Company ) . options ( joinedload ( '<STR_LIT>' ) ) . order_by ( Company . name ) . all ( ) , <EOL> [ <EOL> Company ( name = '<STR_LIT>' , engineers = [ JuniorEngineer ( name = '<STR_LIT>' ) ] ) , <EOL> Company ( name = '<STR_LIT>' , engineers = [ Engineer ( name = '<STR_LIT>' ) ] ) <EOL> ] <EOL> ) <EOL> sess . expunge_all ( ) <EOL> eq_ ( sess . query ( Company , Employee ) . join ( Company . engineers ) . order_by ( Company . name ) . all ( ) , <EOL> [ <EOL> ( Company ( name = '<STR_LIT>' ) , JuniorEngineer ( name = '<STR_LIT>' ) ) , <EOL> ( Company ( name = '<STR_LIT>' ) , Engineer ( name = '<STR_LIT>' ) ) <EOL> ] <EOL> ) <EOL> sess . expunge_all ( ) <EOL> eq_ ( sess . query ( Company , Engineer ) . join ( Company . engineers ) . order_by ( Company . name ) . all ( ) , <EOL> [ <EOL> ( Company ( name = '<STR_LIT>' ) , JuniorEngineer ( name = '<STR_LIT>' ) ) , <EOL> ( Company ( name = '<STR_LIT>' ) , Engineer ( name = '<STR_LIT>' ) ) <EOL> ] <EOL> ) <EOL> sess . expunge_all ( ) <EOL> eq_ ( sess . query ( Company ) . join ( Company . engineers ) . filter ( Engineer . name . in_ ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) . all ( ) , <EOL> [ <EOL> Company ( name = '<STR_LIT>' ) <EOL> ] <EOL> ) <EOL> @ testing . fails_on_everything_except ( ) <EOL> def go ( ) : <EOL> sess . expunge_all ( ) <EOL> eq_ ( sess . query ( Company ) . filter ( Company . company_id == Engineer . company_id ) . filter ( Engineer . name . in_ ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) . all ( ) , <EOL> [ <EOL> Company ( name = '<STR_LIT>' ) <EOL> ] <EOL> ) <EOL> go ( ) <EOL> class ManyToManyToSingleTest ( fixtures . MappedTest , AssertsCompiledSQL ) : <EOL> __dialect__ = '<STR_LIT:default>' <EOL> @ classmethod <EOL> def define_tables ( cls , metadata ) : <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True , <EOL> test_needs_autoincrement = True ) <EOL> ) <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT>' , Integer , <EOL> ForeignKey ( '<STR_LIT>' ) , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , Integer , <EOL> ForeignKey ( '<STR_LIT>' ) , primary_key = True ) , <EOL> ) <EOL> Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT:id>' , Integer , primary_key = True , <EOL> test_needs_autoincrement = True ) , <EOL> Column ( '<STR_LIT>' , String ( <NUM_LIT:20> ) ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT:20> ) ) <EOL> ) <EOL> @ classmethod <EOL> def setup_classes ( cls ) : <EOL> class Parent ( cls . Comparable ) : <EOL> pass <EOL> class Child ( cls . Comparable ) : <EOL> pass <EOL> class SubChild1 ( Child ) : <EOL> pass <EOL> class SubChild2 ( Child ) : <EOL> pass <EOL> @ classmethod <EOL> def setup_mappers ( cls ) : <EOL> mapper ( cls . classes . Parent , cls . tables . parent , properties = { <EOL> "<STR_LIT>" : relationship ( cls . classes . SubChild1 , <EOL> secondary = cls . tables . m2m , <EOL> uselist = False ) , <EOL> "<STR_LIT>" : relationship ( cls . classes . SubChild2 , <EOL> secondary = cls . tables . m2m ) <EOL> } ) <EOL> mapper ( cls . classes . Child , cls . tables . child , <EOL> polymorphic_on = cls . tables . child . c . discriminator ) <EOL> mapper ( cls . classes . SubChild1 , inherits = cls . classes . Child , <EOL> polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( cls . classes . SubChild2 , inherits = cls . classes . Child , <EOL> polymorphic_identity = '<STR_LIT>' ) <EOL> @ classmethod <EOL> def insert_data ( cls ) : <EOL> Parent = cls . classes . Parent <EOL> SubChild1 = cls . classes . SubChild1 <EOL> SubChild2 = cls . classes . SubChild2 <EOL> s = Session ( ) <EOL> s . add_all ( [ <EOL> Parent ( s1 = SubChild1 ( name = '<STR_LIT>' ) , <EOL> s2 = [ SubChild2 ( name = "<STR_LIT>" ) , SubChild2 ( name = "<STR_LIT>" ) ] <EOL> ) , <EOL> ] ) <EOL> s . commit ( ) <EOL> def test_eager_join ( self ) : <EOL> Parent = self . classes . Parent <EOL> SubChild1 = self . classes . SubChild1 <EOL> s = Session ( ) <EOL> p1 = s . query ( Parent ) . options ( joinedload ( Parent . s1 ) ) . all ( ) [ <NUM_LIT:0> ] <EOL> eq_ ( p1 . __dict__ [ '<STR_LIT>' ] , SubChild1 ( name = '<STR_LIT>' ) ) <EOL> def test_manual_join ( self ) : <EOL> Parent = self . classes . Parent <EOL> Child = self . classes . Child <EOL> SubChild1 = self . classes . SubChild1 <EOL> s = Session ( ) <EOL> p1 , c1 = s . query ( Parent , Child ) . outerjoin ( Parent . s1 ) . all ( ) [ <NUM_LIT:0> ] <EOL> eq_ ( c1 , SubChild1 ( name = '<STR_LIT>' ) ) <EOL> def test_assert_join_sql ( self ) : <EOL> Parent = self . classes . Parent <EOL> Child = self . classes . Child <EOL> s = Session ( ) <EOL> self . assert_compile ( <EOL> s . query ( Parent , Child ) . outerjoin ( Parent . s1 ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_assert_joinedload_sql ( self ) : <EOL> Parent = self . classes . Parent <EOL> Child = self . classes . Child <EOL> s = Session ( ) <EOL> self . assert_compile ( <EOL> s . query ( Parent ) . options ( joinedload ( Parent . s1 ) ) , <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> class SingleOnJoinedTest ( fixtures . MappedTest ) : <EOL> @ classmethod <EOL> def define_tables ( cls , metadata ) : <EOL> global persons_table , employees_table <EOL> persons_table = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT>' , Integer , primary_key = True , test_needs_autoincrement = True ) , <EOL> Column ( '<STR_LIT:name>' , String ( <NUM_LIT:50> ) ) , <EOL> Column ( '<STR_LIT:type>' , String ( <NUM_LIT:20> ) , nullable = False ) <EOL> ) <EOL> employees_table = Table ( '<STR_LIT>' , metadata , <EOL> Column ( '<STR_LIT>' , Integer , ForeignKey ( '<STR_LIT>' ) , primary_key = True ) , <EOL> Column ( '<STR_LIT>' , String ( <NUM_LIT:50> ) ) , <EOL> Column ( '<STR_LIT>' , String ( <NUM_LIT:50> ) ) , <EOL> ) <EOL> def test_single_on_joined ( self ) : <EOL> class Person ( fixtures . ComparableEntity ) : <EOL> pass <EOL> class Employee ( Person ) : <EOL> pass <EOL> class Manager ( Employee ) : <EOL> pass <EOL> mapper ( Person , persons_table , polymorphic_on = persons_table . c . type , <EOL> polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( Employee , employees_table , inherits = Person , polymorphic_identity = '<STR_LIT>' ) <EOL> mapper ( Manager , inherits = Employee , polymorphic_identity = '<STR_LIT>' ) <EOL> sess = create_session ( ) <EOL> sess . add ( Person ( name = '<STR_LIT>' ) ) <EOL> sess . add ( Employee ( name = '<STR_LIT>' , employee_data = '<STR_LIT>' ) ) <EOL> sess . add ( Manager ( name = '<STR_LIT>' , employee_data = '<STR_LIT>' , manager_data = '<STR_LIT>' ) ) <EOL> sess . flush ( ) <EOL> sess . expunge_all ( ) <EOL> eq_ ( sess . query ( Person ) . order_by ( Person . person_id ) . all ( ) , [ <EOL> Person ( name = '<STR_LIT>' ) , <EOL> Employee ( name = '<STR_LIT>' , employee_data = '<STR_LIT>' ) , <EOL> Manager ( name = '<STR_LIT>' , employee_data = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> ] ) <EOL> sess . expunge_all ( ) <EOL> eq_ ( sess . query ( Employee ) . order_by ( Person . person_id ) . all ( ) , [ <EOL> Employee ( name = '<STR_LIT>' , employee_data = '<STR_LIT>' ) , <EOL> Manager ( name = '<STR_LIT>' , employee_data = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> ] ) <EOL> sess . expunge_all ( ) <EOL> eq_ ( sess . query ( Manager ) . order_by ( Person . person_id ) . all ( ) , [ <EOL> Manager ( name = '<STR_LIT>' , employee_data = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> ] ) <EOL> sess . expunge_all ( ) <EOL> def go ( ) : <EOL> eq_ ( sess . query ( Person ) . with_polymorphic ( '<STR_LIT:*>' ) . order_by ( Person . person_id ) . all ( ) , [ <EOL> Person ( name = '<STR_LIT>' ) , <EOL> Employee ( name = '<STR_LIT>' , employee_data = '<STR_LIT>' ) , <EOL> Manager ( name = '<STR_LIT>' , employee_data = '<STR_LIT>' , manager_data = '<STR_LIT>' ) <EOL> ] ) <EOL> self . assert_sql_count ( testing . db , go , <NUM_LIT:1> ) </s>
