Hello Daniel, I suggest you to normalized your schema before using feature like list:reference that impose denormalisation to work... If your model is only a bit complexe you will be rapidly always making trade off between ease of implementation of interface with web2py feature and good design practices... Web2py allow ease prototyping that pretty nice if you follow the concept of one table - one form, but you have to build your own complex controllers functions for complex schema to follow good design practices don't fall into the pit of rapid gain at interface level because you will pay the price later for sure... You will have to refactor your model and your app and migrate data into new schema... That one side...
The other side... Agile tell that you should rapidly prototyping system that respond to the need before any thing else and web2py allow you to develop really fast... So... You maybe have to keep in mind that you will have to refactor to respond you client need rapidly. The problem you will face is that your client will start to ask questions when, because of refactoring, you will tell him that new feature will take a lot more time... For sure many to many relation need custom form build with SQLFORM.factory or helpers... Also if you want SQLFORM.factory to work pay attention to the name of your primary key (don't use the same name for pk and fk) and duplicate field name in the differents tables you have because _filter_fields function will fail... Hope it helps. Richard On Tue, Nov 8, 2011 at 1:18 PM, demetrio <[email protected]> wrote: > Hi everyone, > > i'm starting a new project with web2py, and now i'm defining the model > of the app and i have some questions. > > the "classical" and simplified model (there are lots of tables but the > questions are about those) is something like: > > Table 'companies' > - id_company > - name > - .... > > Table 'guild' > - id_guild > - name > - .... > > Table 'construction' (i don't really know if "construction" is the > correct english word for this example, or maybe "building_lot") > - id_construction > - name > - .... > > And now I have to make the relations. In this case one companies can > have many guilds (i.e: the company 'company1' owns to the 'painters' > guild and the 'doors' guild). This relation would be easy in web2py > with a list:reference. > > But the case is that in a building lot, can have one company working > with an specific guild, and in other building lot, the same company > working with another guild. > > For example: > In the construction "A" of 5 apartments, the company "company1" > only works installing windows. > In the construction "B" of 20 apartments, the company "company1" > only works painting the walls. > > In a classic table_has_table model, I could have this: > > Table "company_has_guild": > - id_company_has_guild > - id_company > - id_guild > > And: > > Table "construction_has_company_has_guild" (and at this moment don't > know if this is the best way to make this relation...) > - id_construction > - id_company_has_guild > > As I have mentioned before, the first relation (company_has_guilds) > with web2py would be easy: > > db.define_table("guilds", > Field("name", "string") > ) > > db.define_table("company", > Field("name", "string"), > Field("guilds", "list:reference guilds") > ) > > Any suggestions about the creation of the second relation > (construction_has_company_has_guild)? Or I have to create the > "classic" table_has_table model? In this case, there is some efficient > way to make it in web2py? > > Thanks in advance! > Daniel

