OK, thanks, this was part of the ActiveRecord kind of approach I was playing with, which after reading your article at zzzeek and the alternative described there I will probably shelve.
On Apr 6, 9:59 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: > On Apr 6, 2011, at 6:38 AM, farcat wrote: > > > Thank you, > > > I now experiment with putting session.add and session.flush in > > object.__init__ .. > > > Are there any general disadvantages of that approach? > > Using add() inside of __init__ is somewhat common. Using flush() has the > significant downside that flushes occur too often which is wasteful and > performs poorly for larger scale operations (like bulk loads and such). The > ORM is designed such that primary key identifiers are not needed to be > explicitly accessed outside of a flush except for query situations that wish > to avoid the usage of relationships. When you build your application to be > strongly dependent on primary key identifiers being available within > otherwise fully pending object graphs, you begin to work against the usage > goals of the ORM. > > > > > > > > > > > On Apr 3, 7:44 pm, Michael Bayer <mike...@zzzcomputing.com> wrote: > >> Integer primary key identifiers are generated by the database itself using > >> a variety of techniques which are all database-dependent. This process > >> occurs when the session flushes. > > >> If you read the object relational tutorial starting > >> athttp://www.sqlalchemy.org/docs/orm/tutorial.html#setting-up-the-mappi...working > >> down through the end > >> ofhttp://www.sqlalchemy.org/docs/orm/tutorial.html#adding-new-objectsyouwill > >> see that this interaction is described. > > >> You can of course set .id to any value you'd like and that will be the > >> value used when the flush happens. > > >> On Apr 3, 2011, at 1:09 PM, farcat wrote: > > >>> Hi all, > > >>> I use a kind of dynamic reference from parent_table to other tables. > >>> For that parent_table uses columns table_name and a record_id. This > >>> makes it possible to have a reference from parent_table to any record > >>> in any table in the database. However, say that i want to reference a > >>> record of table_name, i need the record.id to initialize > >>> parent_table.record_id. However, when i create a record and > >>> session.add it to the database, record.id == None. > > >>> I was wondering when and how record.id is initialized and how it can > >>> be forced. > > >>> Cheers, Lars > > >>> -- > >>> 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 > >>> athttp://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 > > athttp://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.