Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Models without simple database persistency


I'm about to start work on a project that uses some complex models. The storage of the entities to which these models map is rather odd:

  • their full details span tables across several databases;
  • reading their details is a combination of reading from these databases plus querying an external service;
  • updates to them do not occur through the database at all but through an external service.

The external service is a server (or several) with which I exchange UDP messages.

These are hard constraints that are out of my control so I have to work with them. The obvious solution is to just have a class for each entity and write getters and setters that interact with the databases and external service like I need them to. But from everything I've read that sounds like it goes against the ethos of Phalcon's models and their ties to ORM. Can Phalcon support models with such a strange persistency layer?

I'm new to Phalcon, MVC and ORMs, so perhaps I'm asking a silly question. I couldn't find anything on this forum or elsewhere however.

edited Jul '16

I would strongly suggest you to avoid ORM in that use case. Not Phalcon's but any ORM out there. Built your own set of classes / API to interact with those abstract API's. UDP messages?! When I worked with a mainframe environment at least we have used UNIX sockets and TCP/IP sockets, never UDP.

Then, take some time to learn Phalcon's components in general, as you declared yourself w/o prior expirience.

If you have some specific question for such diverse environment, post here and I'll try to pair up with my expirience in that matter to advise etc.

Hi, thanks for the quick response!

I'm slowly getting into Phalcon, having taken a short course and followed the tutorial. Now making my way through the documentation, which seems to be the only way to learn it really. Ordinarily I'd pick up the concepts from the tutorials, but Phalcon is so radically different to what I've done before, even with other frameworks.

But it helps to know that I'd better not factor Phalcon's models and ORM into my initial design, so thanks for the advice. They'll still be relevant in some places (the site has users and groups, standard stuff).

And yes, UDP messages. : / There are reasons we've gone that route. Not brilliant reasons, but I'm stuck with it nevertheless. Not looking forward to gracefully handling timeouts and missing messages.

There might be someone very familiar with ORM to override Model base, to achieve what you need by smart extending core (not Zephir). But from my exp, whenever you need to build something that is complex and diverse, it's better to have full control over each aspect.

Once you got into Phalcon, you'll love it. It's very flexibile and highly decoupled which is very important if you wan't to follow SOLID. Take your time.

P.S. If it is in your power, set up Message Broker service (distributed). If not, try to use TCP/IP stack instead. If by chance you are on a same machine with a central system, use UNIX domain sockets to pipe with apps.

Good luck!