0

I am implementing a model design where DB tables are 'resources', and a model can use many 'resources'. When I return a row from a table, it is represented by an 'item'. (This came from a book by Keith Pope, but I've seen it in several other places too).

So, my question is, who should be able to access the resources? In particular:

  • From time to time I'm tempted to let controllers access the resource directly, rather than through the model, for very simple tasks like finding a record. Is this OK?

  • Many of my resources are accessed by more than one model. For example, the 'country' table is accessed by the Organisation Model, and the User model. Presumably this is OK?

Any pointers appreciated, as always!

1 Answer 1

1

Your "resources" should be abstracted into a repository class. Your controllers can access the "resources" through the repository. This gives you the ability to change the underlying "resources" model, without breaking the application. It also gives you a place to put in some security, as needed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.