Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Orm
Pagination and "has_many" releations.
Firestarter
August 2013
I have 2 tables: table
talk_topic
"has many"
talk_posts. Please help me to get from db
limit and offset
talk_posts, but from
Model_Talk_Topic.
I need
something like this:
$data['talk_topic'] = Model_Talk_Topic::find($id, array(
'related' =>array('talk_posts'=>array('limit' =>1),
)
);
i know that i can
Model_Post_Topic, but i need get result, working with
Model_Talk_Topic. All releations in models
are registered correctly,100%.
Harro
August 2013
If you want to generate a table view from a query that has related tables, you should use 'rows_limit' and 'rows_offset'.
By default ORM will limit on the parent only, not on the total result.
Firestarter
August 2013
With this:
$data['talk_topic'] = Model_Talk_Topic::find($id, array(
'related' =>array('talk_posts'=>array('rows_limit' =>1),
)
)
);
I get topic with all posts, but i need to take only 2(not 10). Can you help with litle code?
Harro
August 2013
rows_limit doesn't go on the relation:
$data['talk_topic'] = Model_Talk_Topic::find($id, array(
'related' =>array('talk_posts'), 'rows_limit' =>1)
);
I think. I never use Array notation, I use chaining:
$data['talk_topic'] = Model_Talk_Topic::query()
->where('id', '=', $id)
->related('
talk_posts')
->rows_limit(2)
->get();
will get you 2 objects, which might be the same topic, or two different topics in case the first had less then two posts...
Firestarter
August 2013
Harro Verton
, I am grateful to you for your help. Both of them works great.
Harro
August 2013
You're welcome. Happy coding!
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Firestarter
August 2013
Harro
August 2013