On 6/21/07, Jonathan Swartz <[EMAIL PROTECTED]> wrote:
> Actually, upon reflection, it seems strange to me that column default
> values would have any effect on load().
>
> That is, if I do
>
>      User->new(some_unique_column => 'some value')->load()
>
> is there any legitimate reason I'd want a default value for a
> different unique or primary column to be silently "inserted" into my
> search?

The constructor call and the load() call know nothing about each
other. (This is the only sane arrangement, IMO.)  During load, keys
are considered in turn, starting with primary and then on to the
unique keys (considered in the order they're returned by
meta->unique_keys).  For each key, the columns that make up that key
are checked for defined values.  The check calls the column accessor
methods, and those methods return the default value if there is no
defined value.

In your case, the unique key with the default empty string value is
being considered before the key you really want to use.

If you want to force load() to use a particular unique key, you can
use the use_key => ... parameter, passing the name of the unique key
you want to use.  That means you'll have to name your unique keys
something sane, I guess, but the auto-chosen names shouldn't be too
bad, IIRC.  (Or perhaps the better naming is only in SVN.  Try it and
tell me :)

> This seems like a side-effect of using the same object to both
> initiate a search (with load()) and to insert a new row. I'm sure
> there's some history and good justification behind this decision,
> though.

The load() method isn't really a "search" method, it's a "fill out the
rest of this object from the db, where the particular row is unique
identified by attributes of this object" method.  If you want a
search, you can always ask for one:

    $user = User::Manager->get_users([ some_unique_column => 123)->[0] ]);

-John

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to