I have 3 models.
- Casinos [Table in database of casinos]
- Casino_Languages [Table in database of all possible languages]
- Rel_Casino_Languages [Table in database that stores the languages each casino offers, has 2 columns, casino_id and language_id]
I can successfully get the result set with the following:
<?php $languages = Rel_Casinos_Languages::find(array( "casino_id = :casino_id:", "bind" => array( "casino_id" => $casino->casino_id ) ));
However I wish to order the results alphabetically by the "language_name" in the "Casino_Languages" model. I have set up the relationships as follows:
<?php // Model: Casino_Languages $this->belongsTo("language_id", "\Multiple\Frontend\Models\Rel_Casinos_Languages", "language_id"); // Model: Rel_Casinos_Languages $this->hasOne("language_id", "\Multiple\Frontend\Models\Casino_Languages", "language_id", array( 'alias' => 'language' ));
I then ammended the original find code to look like below:
<?php $languages = Rel_Casinos_Languages::find(array( "casino_id = :casino_id:", "order" => "language.language_name", "bind" => array( "casino_id" => $casino->casino_id ) ));
However I am now getting an error stating:
Phalcon\Mvc\Model\Exception: Unknown model or alias 'language' (1), when preparing: SELECT [Multiple\Frontend\Models\Rel_Casinos_Languages].* FROM [Multiple\Frontend\Models\Rel_Casinos_Languages] WHERE casino_id = :casino_id: ORDER BY language.language_name
Where am I going wrong? If anyone can help, or provide another method that could work I would be very grateful.