On 10/18/06, Tor Hildrum <[EMAIL PROTECTED]> wrote:
>
> On 10/18/06, Lee McFadden <[EMAIL PROTECTED]> wrote:
> >
> > On 10/18/06, Tor Hildrum <[EMAIL PROTECTED]> wrote:
> > >
> > >
> >
> > However, you'd have to be certain that there's nothing in the dict's
> > keys other than in the Book object's column names otherwise SO may
> > complain (not 100% sure on that as I've never looked into how SO
> > initialises a new object).
>
> Perfect.

if that's all the code you have that will also fail, unless ALL your
SO columns are StringCol, since there is no automatic data convertion.

>
> > The *preferred* way of creating a new object is to pass each column
> > and it's data as a keyword/value pair (I'm going to make up the column
> > names for your Book class, but you should get the idea):
> >
> > new_book = Book(title=kw['title'], author=kw['author'],
> > isbn=kw['isbn'], publisher=kw['publisher'])
>
> That's not pretty when the table has a lot of attributes, it also
> lends itself to problems when/if the db-schema is updated.
>
actually pretty here is not an option your talking about db corruption
unless you do the checks.

> I'd rather just use a dict and check it against my db-schema.
>
> One more thing, since I can't access the SQLObject documentation.

why not? it's online.

> **kw holds all the fields in my form, some of them will almost always be 
> empty.
> (there are a lot of information that we won't have for most of the books)
> Say I have a field in my database:
> --------------------------
> Num_revision =   IntCol()
> -------------------------
> Which is the revision number of the book, this will seldom have a value.
> In kw I get:
> kw['Num_revision'] == '' # an empty string
>
> Since Num_revision is an IntCol() I have to cast it. So while checking kw
> I would do something like:
> -----------------------------
> if( schema[key][type] == 'int' ):
>    kw[key] = int( kw[key] )
> -----------------------------
> key is the attribute, in this case Num_revision.
>
no use the build in validators that's what they are for

> Is there any way I can get SQLObject to only require me to pass it the
> key(ISBN), and have all other fields be optional?
>
don't use Alternate id s?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to