Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Proposal: find_attribute_value User.pm #16

hexfusion opened this Issue Feb 21, 2014 · 0 comments


None yet
1 participant

hexfusion commented Feb 21, 2014

Quick method to return an attribute value. This is a rough draft tests etc would need to be done.


# with current logged in user

# with defined user_id

sub find_attribute_value {
    my ($self, $attr, $user_id) = @_;

    # attribute must be set
    unless ($attr) {
              return (0, "Input requires attribute");
    my $attr_rs = $self->result_source->schema->resultset('Attribute');
    my $attribute = $attr_rs->find({ name => $attr });

    # attribute must exist
    unless ($attribute) {
              return (0, "Attribute does not exist.");

    # if user_id is not passed the lets use the current user
    if (!$user_id) {
        $user_id = $self->id;
    my $user_rs = $self->result_source->schema->resultset('User');
    my $user = $user_rs->find( $user_id );

    # find records
    my $user_attribute = $user->find_related('UserAttribute',
                                            {attributes_id => $attribute->id});

    my $user_attribute_value = $user_attribute->find_related('UserAttributeValue',
                                            {user_attributes_id => $user_attribute->id});

    return $user_attribute_value;

@hexfusion hexfusion closed this Mar 25, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment