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 7769157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:05:25+00:00 2026-06-01T16:05:25+00:00

My Persistant model has a ‘status’ field, which can be 0 or 1. I

  • 0

My Persistant model has a ‘status’ field, which can be 0 or 1.

I have a method in my model called getStatusLabel(), which returns “Active” or “Retired”, depending on what status is passed to it.

public function getStatusLabel(required status){
        if (status eq 1)
            return "Active";
        else if (status eq 0)
            return "Retired";
    }

I was thinking it would be great if this could be setup as a computed column, but can’t quite think how to do this. All computed column examples have a SQL Statement as the formula.

Is it possible to call this (or another) method as my formula (making it easier to access via my model), or does the formula need to be a SQL statement?

Alternatively, is is possible to include the logic of the method straight in as the ‘formula’.

When I attempt either, I am getting error: Could not initialize collection so guessing this can’t be done, but would be brilliant if it could, so worth asking.

Many Thanks in advance!

Jason

  • 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-06-01T16:05:26+00:00Added an answer on June 1, 2026 at 4:05 pm

    If you’re using a computed column in SQL Server, you can set the column definition to this:

    CASE WHEN status = 1 THEN 'Active' ELSE 'Retired' END
    

    Set the column to persisted so it doesn’t have to be calculated with each query, and you should then be able to use that in your ORM. Just make sure it’s marked as not updatable or insertable.

    Also, you can have the getStatusLabel method use the status property of the object without passing it in as an argument:

    public function getStatusLabel(){
        if (this.status eq 1)
            return "Active";
        else if (this.status eq 0)
            return "Retired";
    }
    

    If you use that function, just referencing the local status property, does that work as you’d expect?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model called Booking which has a persistent DateTime field. However I
I have created a core data model that has two entities which have a
If I have a Domain Model that has an ID that maps to a
I have a document based application running with core data. The object model has
I have a variable called $result which should store all the results from my
I have a Department entity which has a one-to-many relationship to an Employee entity.
I am trying to design an entity model using JPA2.0 via hibernate. I have
Folks, Apologies if this has been covered in another thread, but I have searched
I have an application that has many views (Using tab bar controller). I want
I've just read about MVC3's new CompareAttribute that you can apply to a model's

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.