vendredi 24 juillet 2015

Data Source Patterns - Where's to put table's level methods?

At my company we work with models based on "Active Record Pattern", the model methods are always related to operations of a single record from the database, for example:

Class User {
    int id;
    string Name;

    public boolean Find (id); // SQL / ORM to return the object based on the user's Id;
    public boolean Save (); // SQL / ORM to save / update a user
    public boolean Delete (); // SQL / ORM to delete a user.
}

// Create the user "John"
Set objUser = new User ();
objUser.Name = "John";
objUser.Save ();

My question is that in relation to the database entity "User", we have methods that are to table level and not record, such as a method "getAllActiveUsers", which returns me a query object of all active users. This type of situation ends up in own ActiveRecord model, which in my opinion does not make sense .. Could you help me to understand what would be the most advisable / elegant to treat this type of situation? I read something about Gateway and Repository Patterns that may be useful for this, but was wondering if anyone has this same trouble and how did you solve ..

Thank you!!

Aucun commentaire:

Enregistrer un commentaire