Welcome Guest, Not a member yet? Register   Sign In
Use functions in extended models in there DB
#1

(This post was last modified: 02-19-2022, 07:56 AM by sprhld.)

Hello!

I'm using extended Models where I have function which are the same request in all extending models. Lets say, a function "getBySlug()" is used in a CommentsModel and in PostModel or so because both have the field "slug". This "BaseModel" does not represent a table in my database. But now I have this point, where the "BaseModel" does represent a table and I would use functions in this model. Thats what I have:

First, there is a "pathModel" which represents my list of paths to every object (which I call subject, just in case you find somewhere in my examble the word subject *g). In this DB I have 2 columns, "id" and "path". Every n/ is the ID of an object. Every object can placed on every level in a path.

Code:
id | path
---|-----------
1  | /1/22/333/
2  | /1/22/334/
...

Then I have a object DB which has also only three field, "id", "subject_id" and "subject_type".

Code:
id | subject_id | subject_type
---|------------|--------------
1  | 1          | region
2  | 22         | legal
3  | 333        | region
...

On the next level, I have for every type an own table with specific columns, but we don't need it here.

The objectModel extends pathModel. In path model I have a function to find the IDs which have no children, which must be the first objects of a navigator. I can't call it because called with $this->firstIds() searches in the table of objects - what I understand. The quest is, is there a way to do so? The structure basically represents a JOIN (maybe not path to object but object to types later on).

What I want to do is something like this in pathModel:

PHP Code:
function firstIds()
{
    $this->like('path''/''AFTER');
    return $this;           // Just a examble
    return $this->findAll() // Just a examble


And call this in objects to work with the return.


Right now, I call the extended model as an new model and I work with this object. But It feels not right :-) There are any other best cases? I hope you understand what where it should goes to :-)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB