Ticket Details
Associations access error
BUG Ticket (pending)
###What happened:
**User.php**
{{{
<?php
namespace app\models;
class User extends \lithium\data\Model {
public $hasMany = array('Post');
}
?>
}}}
**Post.php**
{{{
<?php
namespace app\models;
class Post extends \lithium\data\Model {
public $belongsTo = array('User');
}
?>
}}}
**In controller**
{{{
$users = User::all(array('with' => array('Post')));
}}}
Now i want to loop through user posts, so:
{{{
{% for post in user.posts %}
{{ post.title }}
{% endfor %}
}}}
But there is an error:
```
Fatal error: Uncaught exception 'BadMethodCallException' with message 'No model bound or unhandled method call `posts`.' in /home/me/Php/sites/dev/li3/libraries/li3_twig/libraries/Twig/lib/Twig/Template.php on line 182 BadMethodCallException: No model bound or unhandled method call `posts`
```
If I'll use plain PHP instead of Twig this code will work just fine.
Updates
on 05.05.11
by rafalfilipek
- type was changed to bug
- priority was changed to normal
on 05.19.11
by rafalfilipek