It looks like you're new here. If you want to get involved, click one of these buttons!
Hi,
my model can't output tags because my Primary Key is not named id
Table partner
, with PK = partner.an_id
.
<?php
class Partner_model extends Base_module_model {
protected $key_field = 'an_id';
public $has_many = [
'tags' => [
//'app' => 'my_fuel_tags_model',
FUEL_FOLDER => 'fuel_tags_model',
'where' => ['fuel_tags.context' => 'partner']
]
];
}
Setting relationship between partner and fuel_tags in backend works fine.
If I want to access $partner->tags
in the frontend (via controller) I get an SQL error
Unknown column 'fuel_tags.an_id' in 'where clause'
SELECT fuel_tags
.* FROM fuel_tags
LEFT JOIN fuel_categories
ON fuel_categories
.id
= fuel_tags
.category_id
WHERE fuel_tags
.an_id
IN(9, 11, 10) AND fuel_tags
.context
= 'partner' AND fuel_tags
.published
= 'yes'
Filename: /fuel/modules/fuel/core/MY_Model.php
Line Number: 481
MY_Model->_get_relationship()
seems to access $id_field = $this->_parent_model->key_field();
to create the WHERE IN query $this->_CI->$foreign_model->db()->where_in("{$related_table_name}.".$id_field, $rel_ids);
If my partner
model had an PK field id
instead of an_id
I believe it would work, but I can't rename the field.
What is the solution? How can I access the tags?
Appreciate your advice.
Comments
Any idea?
If you change line 5782 to the following, does it work:
That works, yes. (tested it also with the news modul and this seems to work as well)
Is it possible to include that in the core?
Do you want me to open an issue on Github?
That change has been pushed to the develop branch:
https://github.com/daylightstudio/FUEL-CMS/tree/develop
Perfect! Thank you so much.