Create a Model during runtime

Hi

Is it possible to create a new Model during runtime? The use case is a franchise mgmt system which will create a table for each store to record staff operations. What’s the best practice?

Many thanks.

With the way Fluent works it may be possible with a lot of hacks but practically it won’t be. Assuming the table has the same fields you might be able to make it work with custom functions to specify the table name but I fear that Fluent has table name and model coupled so much that it wouldn’t be possible.

Another option would be to go with SQLKit and ignore Fluent or use a document based DB like Mongo and MongoKitten, which sounds like it would be better suited. Or you could change the design and have a single staff operations table with a store ID on it.

A single staff operations table with Store ID will be a huge dataset for more than ten thousand stores. Create View for each store could be a cure to speedup the query but I don’t know how to do that in Fluent. Any suggestions?

I think you can hack in view support into Fluent but more than likely you’ll need to drop down to raw queries. The discord server would be the best place to ask!

@octavo Do you still have issues with this?