Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Using ORM to best effect
  • Hi,

    I'm struggling to get my head around the ORM. If we take a trivial example:

    I have a twitter like service and I have two tables:
    user id:int username:string name:string email:varchar[256] bio:text
    follows follwer:int followed:int (Where these are the IDs for the user table of the relevant users)

    How would I do it in the ORM so that I could get, say, the username and bio of everyone that follows a user? Is the ORM the best way to do this?

    Thanks!

    [
    The SQL for that is:

    SELECT user.username, user.bio FROM user INNER JOIN follows ON user.id = follows.follower WHERE follows.followed = :my_id
    ]
  • Assuming you have defined a Model_User for the users table, and a Model_Follows for the follows table, and defined the correct relation between the two, the query should be:

    Model_User::query()->select('username', 'bio')->related('follows')->where('follows.followed', '=', $myid)->get();

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion