[orm-devel] No such attribute or function 'oid'
Diedrich Vorberg
orm-devel@mailman.tux4web.de
Tue, 21 Jan 2003 00:34:19 +0100
Good evening!
One thing beforehand: I've got a commission I'm busy working on so I
can't concentrate on ORM as I would like. I'm sorry about this! This
is going to get better in three or maybe four weeks. Then I have to
work on a project that actually involves ORM and I'll be with you
some more. For now I can only give short and maybe shallow (not so
well though through replies). Sorry...
> - Orm uses oid's to identify unique records for backwards
>compatibility reasons.
Yes+no. What ORM does: to every SELECT query's column list it creates
it will prepend "oid,". If a result set contains a column called oid
this column will be treated special and sored in an attribute called
_oid which is accessible through the oid() method. No datatype/column
pair is used for the oid. This inconsistency is due to the ideas I
had for ORM and it's predecessor.
These oids are not actually used anymore. (I think). They only
prevent queries on VIEWS to work :-)
The idea I expressed in the last eMail was to create a datatype/
column pair for oids and have them treated just like any other
column (they would have to be included in your columns dict). This is
a rather substantial modification and I need some time for rather
thorough testing.
> - Ross thinks oid's shouldn't be used for pk's because of the known
>lack of uniqueness (on large databases and/or large tables, see [1]) but
>that using a pk will result in an extra call to the database on INSERTs;
>the extra call retreives the newly inserted pk.
Oids are not used as primary keys unless you specify primaryKey="oid"
for that dbclass. The orm.adapters.pgsql.datasource's insert() method
SELECTs every serial column after the SQL INSERT command is performed.
This does cost extra CPU time, of course. If you want to use oid as
your primaryKey fine! The insert() method will also store the cursor's
lastoid() in the python representation of the newly inserted
object. (This is another place where oids are used: to check whether
an object has been inserted, yet. The mysql datasource sets _oid=1 for
every dbobj it INSERTed.)
> - If ORM used pk's instead of oid's it should be able to deal with
>compound/multi-column pk's. Diedrich has ideas for how to elegantly
>handle the issue of compound/multi-column pk's.
>A question for Diedrich: Will ORM someday support the use of pk's
>(instead of|in addition to) oid's?
It does now! serial pks are the default. (Err...now I see a problem:
they're not only the default: they're the only option). If you want to
use oids set the dbclass' primaryKey="oid" and things should work
fine. This is not tested very much, I'm afraid, since I'm using SERIAL
columns, too.
Basically any single column can be a pk. I think this could be a
problem: only SERIAL columns will be retrieved from the db after an
INSERT. Columns with constrains or defaults will not be updated. I
was thinking about introducing a mechanism to cope with this kind of
situation.
>In response to Diedrich's request for an example of compound primary key:
>"Could you send me with a real world example in SQL?"
>Here's a simple example that allows me to relate a funding source
>(Contract, Work Authorization, Purchase Order; represents money against
>which I can bill my clients) to zero or more invoices (or multiple
>funding sources to an invoice). It has only two fields and both
>together define the primary key:
>
>CREATE TABLE "invoice_funding" (
> "invoice_id" integer NOT NULL,
> "funding_source_id" integer NOT NULL,
> Constraint "invoice_funding_pkey" Primary Key ("invoice_id",
>"funding_source_id")
>);
Thanks, I'll look into this as time permits, I promise!
Hm... looking at this: isn't this a case for a many2many relation and
this is the 'matrixTable'? Perhaps I'm too tired... :-( Anyway in
that case the CONSTRAINT doesn't touch ORM. Or does it? Or rather
not? Sorry... good night...:-))
Diedrich
--
_..._ Diedrich Vorberg
.' '.
/ _ _ \ http://www.tux4web.de
| (o)_(o) | info@tux4web.de
\( ) / .---.
//'._.'\ \ / \ Internet Dienstleistungen
// . \ \ \.@-@./ und 'Consulting'.
|| . \ \ /`\_/`\
|\ : / | // _ \\ Linux Rules!
\ `) ' (` /_ | \ )|_
_)``".____,.'"` (_ /`\_`> <_/ \
) )'--'( ( \__/'---'\__/
'---` `---`