Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Best way to select metadata for user?
  • I'm sure someone else has run across this, so I'll throw this question out here ... I'm using OrmAuth and need an easy way to query metadata associated with a user based on a username.  When I run the migration, there are multiple tables created but the ones I am focused on are "users" and "users_metadata".  I'm sure I need to use some kind of JOIN, but I don't have too much experience with SQL joins so any help would be greatly appreciated!
  • You don't have to do that, ORM will take care of that for you.

    The metadata table is accessable as an EAV (entity-attribute-value) container, so if your user has a metdata property 'fullname', you can access it as if it were a property of the user object, like $user->fullname. ORM will fetch it for you in the background.

    If you need direct access to all user metadata at once, you can access the $user->metadata relation. It returns an array with a metadata model object for each record, just like any other ORM relation.

    And if you need everything at once, you can even do

    $users = \Model\Auth_User::find('all', array('related' => array('metadata')));

    which will fetch all users, and for every user all metadata.
  • Does my model need to extend any particular class for this functionality?  I currently have:

    class User extends \Model
  • Actually, the above won't work.  I am attempting to manipulate data prior to the user logging in.  The entire auth framework relies upon the user actually being logged in but seems to completely ignore any actions that a developer would want to perform pre-login.
  • For Ormauth, all models are included in the Auth package. If you insist you want your own model, it should extend the Auth one:

    class User extend \Model\Auth_User {}

    yours extends \Model, which is not an ORM model, and is not going to work anyway. Perhaps you should read up on ORM, to see how it works and what it does.

    And obviously the Orm package must be loaded for Ormauth to work...

Howdy, Stranger!

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

In this Discussion