I have two tables with this schmea:
mysql> show columns from table_1;
+-------------+------------------+------+-----+---------------------+-----------
| Field | Type | Null | Key | Default | Extra
+-------------+------------------+------+-----+---------------------+-----------
| id | int(10) unsigned | NO | PRI | NULL | auto_incre
| id_world | int(11) | NO | | NULL |
| key | varchar(255) | NO | | NULL |
| name | varchar(255) | NO | | NULL |
| description | varchar(255) | NO | | NULL |
| level | int(11) | NO | | 0 |
| created_at | timestamp | NO | | 0000-00-00 00:00:00 |
| updated_at | timestamp | NO | | 0000-00-00 00:00:00 |
+-------------+------------------+------+-----+---------------------+-----------
8 rows in set (0.00 sec)
and
mysql> show columns from table_2;
+--------------+------------------+------+-----+---------------------+----------
------+
| Field | Type | Null | Key | Default | Extra
|
+--------------+------------------+------+-----+---------------------+----------
| id | int(10) unsigned | NO | PRI | NULL | auto_incr
| key | varchar(255) | NO | | NULL |
| level | int(11) | NO | | NULL |
| name | varchar(255) | NO | | NULL |
| description | varchar(255) | NO | | NULL |
| price | int(11) | NO | | NULL |
| amount | int(11) | NO | | NULL |
| created_at | timestamp | NO | | 0000-00-00 00:00:00 |
| updated_at | timestamp | NO | | 0000-00-00 00:00:00 |
+--------------+------------------+------+-----+---------------------+----------
30 rows in set (0.00 sec)
I want to get all fields "from table_2 where table_2.key = table_1.key AND table_2.level = 10" is this the right way with the hasMany option in my model?
my normal query looks like this:
SELECT A.key AS p_key,
A.name AS p_key,
A.description AS p_desc,
A.level AS p_level,
B.key AS r_key,
B.level AS r_level,
B.name AS r_name,
B.description AS r_desc
FROM
table_1 AS A,
table_2 AS B
WHERE
B.key = A.key AND
B.level = '1'