The insert function will return the id.
fk = db.fk_table.insert(name="The Foreign Key")

On Jun 4, 9:48 am, Doug Warren <doug.war...@gmail.com> wrote:
> Hi,
>
> I defined all my tables in my model file and want to have a few
> hundred rows of default foreign keys to maintain 3rd normal form.  So
> I have things in my code such as:
>
> if db(fk_table.id > 0).count() == 0:
>     db.fk_table.insert(name="The Foreign Key")
>
> if db(table2.id > 0).count() == 0:
>     fk = db(db.fk_table.name == "The Foreign Key").select()[0]
>     db.table2.insert(name = "Some name", fk_id = fk.id, field2="some value")
>
> I'm sure there's a better way to get the id of the foreign key than
> doing select()[0].id, but I'm not sure what it is...

Reply via email to