find or find_by_sql: select * and more

Hi,

I'm trying to retrieve ALL fields from an Oracle database table, as
well as a subset of them, under a different name.

The equivalent select statement would be:

SELECT *, NAME_EN AS NAME, DESC_EN AS DESCRIPTION FROM MYTABLE;

The problem is that this isn't allowed (Oracle-specific?). Is there a
way I can do this using Rails' find method?

Thanks,

Chris.

cn u show m d bit code of fields subset

I don't quite understand your question... sorry. But someone suggested
a solution that I like; assuming I could get it to work:

I created the following method in the Model:

  def description
    self[:desc_en]
  end

and in the Controller, I have:

  def by_id_xml
    @my_model = MyModel.find( params[:id] )
    render :xml => @my_model.to_xml
  end

Unfortunately, by_id_xml still returns the same XML structure, with
all of the table's fields, but without the new field "description"...
Is this due to the fact that description is a method and not a class
variable? In which case, is there a way I can tell ActiveRecord to add
the "description" field to the model?

Thanks,

Chris.

to_xml takes a bunch of options for that kind of thing. In particular, the :methods key is an array of methods to call and include in the xml, so in your case

@my_model.to_xml :methods => [:description]
ought to do the job.

Fred

Thanks Fred, that worked.

Chris.

Now I have a new problem, derived from the one above... My Rails code
looks like this:

My problem is solved: I removed "AS DESCRIPTION_I18N" from the SQL
query, because the variable is created in to_xml(), which expects to see
DESC_FR.

Thanks to Fred,

Chris.