You can create schemas on the fly with web2py (web2py will do the
alter table). It would be possible to allow redefining a table within
the same http request but why?
you can also do this:
def associate(t1, t2, *fields):
db = t1._db
f1 = t1._tablename+'_id'
f2 = t2._tablename+'_id'
name = t1._tablename+'_'+t2._tablename
t3 = db.define_table(name,Field(f1,t1),Field(f2,t2),*fields)
return (t3[f1]==
t1.id)&(t3[f2]==
t2.id)
def link(association,rec1,rec2):
table = association.first.first.table
f1,f2 = table.fields[1:3]
return table.insert(**{f1:
rec1.id,f2:
rec2.id})
db.define_table('person',Field('name'))
db.define_table('dog',Field('name'))
john = db.person.insert(name = 'John')
snoopy = db.dog.insert(name = 'Snoopy')
ownership = associate(db.person,db.dog)
link(ownership, john, snoopy)
rows = db(ownership).select(
db.person.name,
db.dog.name)
On Jan 30, 3:15 am, Chnrxn <
chn...@gmail.com> wrote:
> It brings in the power of NoSQL. On my part, having used SQLObject,
> SQLAlchemy, DAL, and RedBean, I find that Redbean does a wonderful job
> of removing obstacles, no doubt many might deem them to be
> insignificant, during development. It does make a big difference for
> me, especially during development phase when the schema design changes
> frequently.
>
> In a sentence, this is the ability to create/adjust schemas on-the-
> fly. (#1)
>
> The other major advantage is that RedBean makes associating objects in
> different tables a no-brainer without having to deal with foreign keys
> explicitly, i.e. an Association Manager (#2)
>
>
http://redbeanphp.com/community/wiki/index.php/Associationshttp://redbeanphp.com/community/wiki/index.php/Advanced_Associations