B
B
Blumfontein2014-01-21 08:16:52
PHP
Blumfontein, 2014-01-21 08:16:52

Global filters in Propel ORM

I started to study this ORM, and it seemed very tasty to me. But the question arose: is it possible to somehow implement the mechanism of global filters using Propel. Let me explain with an example.
Let's say I'm doing some SaaS. I have about a dozen models, each of which has a company_id field, obviously indicating company affiliation. Thus, in each request, I need to write an additional condition filterByCompanyId ($ id), and in each INSERT, I need to substitute the company ID separately.
It would be very cool if you could write a condition somewhere in the base controller once, something like $propel->globalFilterByCompanyId($id), then this condition is automatically added to each request for models that contain the company_id field ( and not only in SELECT queries, but also in DELETE, UPDATE, INSERT).
This is good not only for reducing the amount of code, but also for improving the decomposition of logic: we have written a condition for a company, then we completely abstract from a specific company and write all further logic as if we were making a website for one company.
If Propel can't do this, it would be interesting to know if other ORMs can, because I haven't seen it anywhere else.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yakov Akulov, 2014-01-21
@jakulov

I don't know about Propel.
I usually use Doctrine and there are Repository and ObjectManager
. Using inheritance, it is easy to override standard methods in them and add the necessary conditions to them.

R
Roman Makarov, 2014-01-21
@vollossy

There is no such method, as far as I know, in Propel. And I think that's why. What you are talking about is not really an ORM layer, it is already business logic and developers simply cannot predict all use cases for their tool.
And in the end, you can simply set up links in the Company model and make a selection by related fields (it will not be so easy with dml)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question