I have a design issue I need to resolve before starting building my app.
I have a complex data structure which is saved in several small simple tables.
In order to query my DB for a complete comprehensive result I use stored functions.
This is true in majority of cases, and I seldom need only one table data for a certain view.
To make it short Iām having issues understanding what I need exactly in terms of MVC.
Iāll take an example of one view I have. this one view shows results of tests that are ran and their data is stored in a DB server.
The tests track numerous attributes and I use stored procedure to query the data in a way that can tell me what happened in the test.
This view will be controlled by one controller, e.g. resultController which actually wonāt do much more then render the view as its data is coming out in a controlled manner from the stored function.
And what about the model? the model only needs to query out the stored function data, it has no data input.
Do I implement a model for this? How do I do that?
What is the recommended methodology in this case ?
By the way, this situation is true through out most of my application, so Iām wondering if this is a good practice or a bad design? I already have a working site that serves me and uses this stored functions and it is working well.
How do I create a model for a stored function? I know how it is done for a table, but not for a function.
Is it okay to say that in my MVC the controller actually serves the view functionality more than it handles the model, if at all.
There is no correlation between the controller and the model other then just get data from it.
The view needs to get data from a couple of stored functions, and translate it to functionality in the view, so in my case letās say that my view is called āaViewā and my controller is called āaControllerā, but do I need āaModelā?
There is no such model in my DB, this "a" entity is constructed from a couple of stored functions in my DB. So basically "a" is a web app entity and not a DB entity/table.
An AR model is designed to work with single and related tables or database views, not for usage with stored procedures.
This is because it uses the db schema behind, read and caching the metadataā¦ This is not possible for stored procedures (with custom input/output params ā¦).
Do you know another framework/programming language that can handle this on the fly??
I would create one or more custom components (maybe inherited from CSqlDataProvider) the handles the stored procedure stuff - depending on the context: DbBookingProvider, DbStatisticsProvider ā¦
I would more think in ācontext-modelsā than in āar-modelsā and single tables/views.
Or I would add a method to an existing AR-model:
Model Basket (with a single basket table behind)
When booking the basket you have a sp ābookBasket(ā¦)ā where you have to do a lot of db validations/checks.
In this case I would add a method ābookBasketā to the model āBasketā that fires the sp.
I would create models that encapsulate the data you need in the views. I would probably use a data source object to create an API for retrieving them, so if itās ever switched out the API holds true. The models would not be active records however, just behave in a similar fashion by having the appropriate public attributes.