nah its a bug...will fix in a few
On Nov 29, 2007, at 12:25 PM, Kapil Thangavelu wrote:
> from sqlalchemy import Column, MetaData, Table, types, ForeignKey,
> Index, create_engine
> from sqlalchemy.orm import mapper, relation, backref, session
> from sqlalchemy.orm.collections import attribute_mapped_collection
>
>
> metadata = MetaData()
>
> concepts_table = Table("concepts", metadata,
> Column("id", types.Integer, primary_key=True),
> Column("name", types.Unicode, nullable=True),
> Column("parent", types.Integer,
> ForeignKey("concepts.id") )
> )
>
> class Concept( object ): pass
>
> mapper(Concept, concepts_table, properties={
> 'children': relation(Concept, cascade="all",
> backref=backref("parent_node",
> remote_side=[concepts_table.c.id]),
>
> collection_class=attribute_mapped_collection('name'),
> lazy=False, join_depth=3)})
>
> db = create_engine('sqlite://', echo=True)
>
> metadata.bind = db
> metadata.drop_all()
> metadata.create_all()
>
> data = [
> [ 3, u'Audiences', None ],
> [ 4, u'External', 3 ],
> [ 5, u'Media', 4 ],
> [ 6, u'Vendors', 4 ],
> [ 7, u'Researchers', 4 ],
> [ 8, u'Grantees', 4 ],
> [ 9, u'Government', 4 ],
> [ 10, u'Managers', 9 ],
> [ 11, u'Officials', 9 ],
> [ 12, u'Educational', 4 ],
> [ 13, u'Education product developers', 12 ],
> [ 14, u'Educational Purposes', 12 ],
> [ 15, u'Accessibility', 14 ],
> [ 16, u'Educational level', 14 ],
> [ 17, u'Disciplines', 14 ],
> [ 18, u'Competency', 14 ],
> [ 19, u'Skill level', 14 ],
> [ 20, u'Prerequisites', 14 ],
> [ 21, u'Restrictions', 14 ],
> [ 22, u'Educational objectives', 14 ],
> [ 23, u'Security level', 14 ],
> [ 24, u'Ideas', 14 ],
> [ 25, u'Educational Contexts', 12 ],
> [ 26, u'School', 25 ],
> [ 27, u'Training', 25 ],
> [ 28, u'Higher education', 25 ],
> [ 29, u'Students', 12 ],
> [ 30, u'Middle School', 29 ],
> [ 31, u'Graduate', 29 ],
> [ 32, u'High School', 29 ],
> [ 33, u'Post-graduate', 29 ],
> [ 34, u'Undergraduate', 29 ],
> [ 35, u'Adult', 29 ],
> [ 36, u'Elementary School', 29 ],
> [ 37, u'Managers', 12 ],
> [ 38, u'Educators', 12 ],
> [ 39, u'Educational Roles', 12 ],
> [ 40, u'Contributors', 39 ],
> [ 41, u'Validators', 40 ],
> [ 42, u'Technical implementers', 40 ],
> [ 43, u'Script writers', 40 ],
> [ 44, u'Publishers', 40 ],
> [ 45, u'Instructional designers', 40 ],
> [ 46, u'Subject matter experts', 45 ],
> [ 47, u'Graphic designers', 40 ],
> [ 48, u'Educational validators', 40 ],
> [ 49, u'Terminators', 40 ],
> [ 50, u'Editors', 40 ],
> [ 51, u'Technical validators', 40 ],
> [ 52, u'Initiators', 40 ],
> [ 53, u'End user roles', 39 ],
> [ 54, u'Managers', 53 ],
> [ 55, u'Students', 53 ],
> [ 56, u'Middle School', 55 ],
> [ 57, u'Graduate', 55 ],
> [ 58, u'High School', 55 ],
> [ 59, u'Post-graduate', 55 ],
> [ 60, u'Undergraduate', 55 ],
> [ 61, u'Adult', 55 ],
> [ 62, u'Elementary School', 55 ],
> [ 63, u'Educators', 53 ],
> [ 64, u'Authors', 53 ],
> [ 65, u'Parents', 12 ],
> [ 66, u'General public', 4 ],
> [ 67, u'Engineers (External)', 4 ],
> [ 68, u'Scientists (External)', 4 ],
> [ 69, u'Contractors', 4 ],
> [ 70, u'Internal', 3 ],
> [ 71, u'Employees', 70 ],
> [ 72, u'Business Staff (Internal)', 71 ],
> [ 73, u'Administrative Staff (Internal)', 72 ],
> [ 74, u'Finance Staff (Internal)', 72 ],
> [ 75, u'Managers (Internal)', 72 ],
> [ 76, u'HR Staff (Internal)', 72 ],
> [ 77, u'Engineers (Internal)', 71 ],
> [ 78, u'Scientists (Internal)', 71 ],
> ]
>
> for d in data:
> concepts_table.insert( values=d ).execute()
>
> s = session.Session()
> for i in s.query( Concept ).all():
> print i.name
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---