Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Get list of inserted id's of many relation
Is it possible to get list of IDs of inserted relation model. Example:
$list = \Model_List::find(1);
foreach(\Input::post('list_items') as $list_item):
$list->items = new \Model_List(array($properties here));
Can I get the ID's of the inserted list items here? I know I could simply loop trough the list items, but since I can add list items to existing list, I need to get only last inserted items...
Is this the same question as
nope I have nothing to do with that Q. looks very similar on first look
Then I don't understand your question.
From your code snippit it looks like you get a list of id's posted that you want to use to assign to a models relation?
Oh, is the question the other way around, how can I get an array of PK's from a relation?
In that case:
$ids = array_keys($list->items);
this only works for saved relations, newly assigned relations don't have a valid array key.
>>Oh, is the question the other way around, how can I get an array of PK's from a relation?
Yes PK's of relation
>>this only works for saved relations, newly assigned relations don't have a valid array key.
Yeah but I would need only for new saved relations, some might already exist from before... I guess I can't do this ...
No, there is no other way then looping over the relation.
Ok thanks anyway!
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion