Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Attribute does not do typecasting as it should #121

Closed
ged opened this issue Mar 26, 2012 · 4 comments
Closed

Read Attribute does not do typecasting as it should #121

ged opened this issue Mar 26, 2012 · 4 comments

Comments

@ged
Copy link
Owner

ged commented Mar 26, 2012

Original report by lazarius (Bitbucket: lazarius, GitHub: lazarius).


I have an issue when I use 'read_attribute' on a timestamp attribute of my model, it return a String object instead of a DateTime object.

def start_date
read_attribute(:start_date)
end

event.startdate => "2012-02-06 07:00:00" #String

instead of Mon, 06 Feb 2012 07:00:00 0000 # DateTime

Using Rails 3.2.2 and Postgres 9.1

@ged
Copy link
Owner Author

ged commented Mar 26, 2012

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


The 'pg' driver intentionally does not do any typecasting for any field. See [[http://wiki.postgresql.org/wiki/Driver_development|the PostgreSQL wiki page on Driver Development]] for the reasons behind the design decisions.

@ged ged closed this as completed Mar 26, 2012
@ged
Copy link
Owner Author

ged commented Mar 26, 2012

Original comment by lazarius (Bitbucket: lazarius, GitHub: lazarius).


I agree with the wiki that you need to provide a way to access to the "raw" data, but is not that the function of "read_attribute_before_type_cast" instead of "read_attribute" since it brake the model behavior if you use another driver (e.g. mysql2) ?

@ged
Copy link
Owner Author

ged commented Mar 26, 2012

Original comment by Michael Granger (Bitbucket: ged, GitHub: ged).


That may be, but read_attribute is not implemented in the pg gem, it's implemented by whatever layer you're using on top of it. I'd guess ActiveRecord based on the fact that you're using Rails. You can't "use another driver" with pg, because it is the driver. Does that make sense?

I suspect you really want to be filing a ticket with whoever maintains ActiveRecord's PostgreSQL adapter.

@ged
Copy link
Owner Author

ged commented Mar 27, 2012

Original comment by lazarius (Bitbucket: lazarius, GitHub: lazarius).


Ok I see your point, I though this was redefine by each driver. I have fill a ticket on the rails tracker on github (rails/rails#5607)

Thanks for your help

@ged ged added this to the Pending milestone Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant