Not signed in (Sign In)
Welcome Guest!
Want to take part in these discussions? If you have an account, sign in now.
If you don't have an account, apply for one now.
    • CommentAuthorThijs
    • CommentTimeJan 19th 2008
     

    Is it possible in Akelos to set something like this in a model (example from api.rubyonrails.com):

    class User < ActiveRecord::Base
       def full_name
         "#{first_name}. #{last_name}"
       end
    end
    

    So I could use:

    $User->collect($User->findBy('role_id',2),'full_name','id')
    

    .. in a view to make a selection menu with the full names of people?

    • CommentAuthorKaste
    • CommentTimeJan 19th 2008
     

    this would be

    class User...
    function getFullName()
    {
        return $this->firstname . $this->lastename;
    }
    
    • CommentAuthorThijs
    • CommentTimeJan 21st 2008
     

    ah, okay.

    Didn't know I should use get + camelcased name, because I tried:

    function full_name()
    {
       return $this->first_name.' '.$this->last_name;
    }
    

    .. but that didn't work.

    Thanks!

    • CommentAuthorThijs
    • CommentTimeJan 21st 2008 edited
     

    aha, so that's what virtual or transparent attributes are, being discussed in this post. (learning new tricks every day)

    I’ve got another one: I want to make a collection of a model that does not have a name column, the names are defined by a belongs_to association to another column (energysourcename) which has localized name columns.

    So I could do this:

    function getName()
    {
       $this->energysourcename->load();
       return $this->energysourcename->{$_SESSION['lang'].'_name'};
    }
    

    But maybe there's a nicer, shorthand way of doing it without using $_SESSION['lang'] ?

    • CommentAuthorKaste
    • CommentTimeJan 21st 2008
     

    .

    ->getCurrentLocale()
    
    • CommentAuthorsalavert
    • CommentTimeJan 22nd 2008
     

    Or try with

    class Person extends ActiveRecord
    {
        var $combined_attributes = array(array('name', "%s %s", 'first_name', 'last_name'));
    }
    

    Now you can user Person->get('name')

Add your comments
    Username Password
  • Format comments as