Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7554633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:23:20+00:00 2026-05-30T11:23:20+00:00

Assume the following association among three tables in a database: //working with three tables

  • 0

Assume the following association among three tables in a database:

    //working with three tables a client 'has one' business
    //and a business has many business hours.

The following would give us an array of Activerecord objects:

$this->client->business->businesshours

and we would have to pull an object form the array to get its column value:

$this->client->business->businesshours[0]->start_time

Since I am new to PHP Activerecord, what are some ways of proceeding to pull/sort/use information from an array of objects other than looping with a foreach() loop? Are there methods to sort through the array of objects, pull information based on a column value, any best practices?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:23:21+00:00Added an answer on May 30, 2026 at 11:23 am

    There is not a library-specific practice for sorting or pulling certain businesshour objects out of the result array. If you want to manipulate the returned array of objects you need to use standard PHP array functions like array_map on the result array.

    If you know the sort order or the conditions you want for the returned objects in the result array you should instead specify these in your association declaration so you don’t return objects that you don’t want or need.

    Since you haven’t posted any code you’ll just have to extrapolate to your own situation from this example:

    static $has_many = array(
      array(
        'businesshours',
        'conditions' => array('hour BETWEEN ? AND ?' => array(9, 17)),
        'order' => 'hour ASC'
      )
    );
    

    This association declaration will return only the businesshour objects between 9 and 17 and do it in ascending order. So as you can see, if you constrain your associations to only the records you need, there will be no need to sort or parse the result array once received.

    Sometimes it’s useful to use array_map to get only certain objects from your result array:

    // get $result array
    $new = array_map(function($obj) { if ($obj->hour > 9){ return $obj; } }, $result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume following component tree: A B C A has a private field (called filter)
Assume following code, NSString *str=[[NSString alloc] initWithString:@sagar]; [str autorelease]; I have seen many times
Assume the following table structure: Tables: **Tasks** taskID int PK taskName varchar **Resources** resourceID
Assume the following problem context: 1) In our application, we have a business object
Assume the following schema user_id, tournament_id, round How would I perform a search to
Would any experienced Erlang programmers out there ever recommend association lists over records? One
Lets assume following classes definition: public class A { public final static String SOME_VALUE;
Assume the following code where sock is a handle to TCP socket that was
Assume the following files: a.php b.php c.php a.php includes c.php b.php includes c.php a.php
Assume the following class: public class MyEnum: IEnumerator { private List<SomeObject> _myList = new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.