If I have something like:
$posts = Post::model()->findAll();
How could I search within $posts for a post by primary key? (As opposed to running a separate database query since the data is already loaded)
Background:
I’m loading data from an external source, based on the primary key of a model. So I run a lookup to find all the models that need updating, and then make a request to the external source, and update the models.
The results (~100) are sent back as an unlabeled array of objects (one of the variables in the object is the primary key), so it seems appropriate to iterate that array, and then update the values on the existing model I’ve already loaded from the database and then save each item.
I’m not against using another method to get all this accomplished, this just seems like the most maintainable way to do it.
I guess simply looping through all posts would be an option:
alternatively, if it is possible, this is prefereable: