• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Derived attribute problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Derived attribute problem


  • Subject: Re: Derived attribute problem
  • From: Ângelo Andrade Cirino <email@hidden>
  • Date: Sun, 23 Mar 2014 12:58:34 -0300

Hi Aaron,

Thank you for your prompt answer. Unfortunately none of the suggestions worked.

1) I can't find any combination of double or single apostrophe that will work. A similar MySQL SELECT statement is as simple as this

select Party.id as partyID, (case status
when 0 then 'Active'
when 1 then 'Inactive'
    end) as fullStatus from Party;

Even this simple derived attribute that returns a constant won't work (from the plist entity file):

{
columnName = fullStatus; 
definition = "'Full Status'"; 
name = fullStatus; 
prototypeName = varchar16; 
}, 

with the following error:

IllegalStateException: sqlStringForAttribute: attempt to generate SQL for attribute 'fullStatus' on entity 'Party' with undefined column name. You must define a column name for this attribute before attempting a database operation.


2) The read format option didn't work either since the attribute is an integer number and the return value is a string. I attempted this format:

if(%P,'Active','Inactive')

and it resulted in this error:

JDBCAdaptorException: Invalid value for getInt() - 'Inactive'


However, this works just fine as a read format:

if(%P,2*%P,5*%P)

But I am stubborn and think that a derived attribute is a desirable attribute. I would like to use it for more complex operations, for example involving concatenation of strings in related entities.

Anyway, trying to figure out what is happening, it occurred to me that my Party entity is a custom class, so I tried a non-custom class with a simple entity to see if the derived attribute would work. And it worked. My simple tentative entity is this:

{
    attributes = (
        {columnName = code; name = code; prototypeName = intNumber; }, 
        {
            columnName = fullStatus; 
            definition = "case code when 0 then 'Active' when 1 then 'Inactive' end"; 
            isReadOnly = Y; 
            name = fullStatus; 
            prototypeName = varchar16; 
            userInfo = {"_EntityModeler" = {generateSource = NO; }; }; 
        }, 
        {allowsNull = N; name = id; prototypeName = id; }
    ); 
    attributesUsedForLocking = (code, id); 
    className = "er.extensions.eof.ERXGenericRecord"; 
    classProperties = (code, fullStatus); 
    externalName = Status; 
    fetchSpecificationDictionary = {}; 
    name = Status; 
    primaryKeyAttributes = (id); 
}

But this isn't a solution for me, since my entity will have a lot of business logic that demands a custom class. Perhaps I should set my Party entity as a ERXGenericRecord and then subclass it to implement the business logic.

The question is, why does EO expect a column for a derived attribute for a custom class and not for a ERXGenericRecord?

By the way, the original Apple EOModeler User Guide doesn't state that a derived attribute will not work for a custom class nor does the documentation states that a derived attribute should be modeled for a generic record.

Angelo

2014-03-23 1:01 GMT-03:00 Aaron Rosenzweig <email@hidden>:
Hi Angelo,

Couple things to try:

1) Remove the single apostrophes surrounding “status” and try again. It is possible that it isn’t parsing properly… don’t column names need to have “double apostrophes” ??? Perhaps MySQL is lax about that but still… Either use no apostrophe or use a “double apostrophe” meaning a single character the shift-apostrophe key. If it is a single apostrophe that is a String in SQL. 

2) Try a different way. Remove all the code you have in the derived part and make this a normal EOAttribute. Put “STATUS” in there by itself. Now go to the “advanced” tab and type what you want in the “Read Format” and check the “read only” box. In the read format you want to use %P for your columnName so you’ll want something like this:

case %P when 0 then 'Active' when 1 then 'Inactive’ end

Honestly, I almost always use the #2 way and never the “derived” way because it is more flexible. I like the idea that I define the column in one box and in another I write something complex but refer to it with %P. 

Try it out and report back.
Aaron Rosenzweig / Chat 'n Bike
e:  email@hidden  t:  (301) 956-2319



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Derived attribute problem
      • From: Aaron Rosenzweig <email@hidden>
    • Re: Derived attribute problem
      • From: Aaron Rosenzweig <email@hidden>
References: 
 >Derived attribute problem (From: Ângelo Andrade Cirino <email@hidden>)
 >Re: Derived attribute problem (From: Aaron Rosenzweig <email@hidden>)

  • Prev by Date: Re: Derived attribute problem
  • Next by Date: Re: Derived attribute problem
  • Previous by thread: Re: Derived attribute problem
  • Next by thread: Re: Derived attribute problem
  • Index(es):
    • Date
    • Thread