Answer the question
In order to leave comments, you need to log in
Yii2 3 tables and 2 ActiveRecord?
Good day.
There are 3 tables and 2 entities, one of the tables contains the general properties, the other 2 contain the details of each entity.
The question of how to instantiate a specific entity class is not worth it, here you can use the single table template, but how to instantiate a specific class with details without additional communication.
"Now I'll rephrase the question correctly how to write my bike with square wheels"
I'm waiting for advice on the subject, I don't need to write about the connection in a particular class with a class of specific details, I know how to do it myself, and if nothing interesting happens, I will implement it like this.
Screenshot of a pseudo database schema:
This is how the database schema will look like, only fields like fieldN will be larger, some fields will intersect, some will not.
relationships:
entities - entity_type1 one to one
entities - entity_type2 one to one
the type field in entities as a condition for selecting a specific table with details, and, accordingly, instantiating a specific active record type.
It's like a single table, only there is one table and many types of objects, and here there are many types and many tables, each table describes a specific type, but each is a successor of a general type.
Answer the question
In order to leave comments, you need to log in
As far as I understand from the question, you have a many-to-many relationship.
If so, viaTable can help
www.yiiframework.com/doc-2.0/yii-db-activequery.ht...
If a DB with support of "views", I think it is possible to use them. And so I advise only with an additional connection. I don't understand why you don't like it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question