Can not get `hasOne` to work


My database has some unusual naming conventions ( not my choice ).
And I can’t seem to get hasOne reference to work ( haven’t even tried hasMany )

        $urlsSearchTerms = new \atk4\data\Model($this->db, ['table'=>'UrlsSearchTerms','id_field'=>'Index','title_field'=>'title']);
        $userUrls =  new \atk4\data\Model($this->db, ['table'=>'UsersUrls','id_field'=>'Index','title_field'=>'Url']);
            //            ->addTitle()


If I run it as is I get atk4\core\Exception: Child element not found.

If I switch addFields for addTitle I get atk4\core\Exception: Element with requested name already exists

What am I doing wrong here? Been breaking my head on this for a while now.


you should specify “their_field” otherwise I think it looks for default id field and not finding it inside ‘uerurls’.

Also it’s probably best if you create dedicated classes for your models.


if you catch the exception, you can dump out it along with extra information, see documentation on ATK Core.


Thanks, is there documentation on using “their_field” because I believe I tried that and it didn’t help.


if you search there are a few mentions. Can you post your ER diagram here, i’ll try to suggest.


I don’t think my employer woud want me to post it here… But I’ll try to get something close


not the entire database of course, just something so we can understand and help. You can create just a test-case.


Ok tried add thier_field and it didn’t help.

                         'their_field' => 'Index'

And I still get the same error

atk4\core\Exception: Child element not found





This is just part of a bigger diagram ( that is also a big mess )

Thanks for your help.