This project is archived and is in readonly mode.
Support for multiparameter attribute assignment on virtual attribute writers
-
Michael Koziarski
- Assigned user set to Eloy Duran
-
Ken Collins
This bit us today too. The fallback to time is a real nice way to handle this IMHO.
-
nagu
This bit me too.
-
Michael Koziarski
Couldn't you use composed_of instead of attr_accessor here? That'll give you the necessary bits to make this work?
Time seems like a nice format but it's a little magical here?
-
Eloy Duran
I'm not quite sure why this was assigned to me.
If it was because of the composed_of replacement that I wrote in the past; Manfred has taken another stab at it: #950 AttributeDecorator, a new take on aggregation.
-
Brennan Dunn
- Assigned user changed from Eloy Duran to Michael Koziarski
Koz,
The reasoning behind not generally resorting to composed_of was done for the sake of consistency. Being that update_attributes blindly sends to the attributes' writer methods, whether or not said writer methods map to an actual DB column, it made sense that special form helpers - i.e., date_select, should 'just work'. Currently, due to the column reflection that happens in #execute_callstack_for_multiparameter_attributes, only writer methods that concretely map to a column are supported.
...I guess I just feel using #composed_of here and mapping the (1i), (2i), etc. parameters is overkill, and all the form helper methods should be able to support model writer methods using #update_attributes.
Lastly, every Time contains a Date, and #foo_time= and #foo_date= would 1) look silly and 2) tack on a lot more foundational code. Otherwise, I don't see any other means to really infer the desired format.
-
Michael Koziarski
I'm just not sold that a default of Time makes sense. The multi
parameter code handles more than just Dates and Times and you can tell
it what the type is by specifying composed_of or something similar.I'd prefer to fix it 'right' rather than just default to time if we're
unsure. Perhaps the best way to do this is to make sure that #950 AttributeDecorator, a new take on aggregation. has
something simple for this case? -
Jon Leighton
Would be great to get this fixed. In the meantime, I thought I'd drop in and say that I found a very hack solution:
class Whatever < ActiveRecord::Base ... attr_accessor :arrival_time columns_hash["arrival_time"] = ActiveRecord::ConnectionAdapters::PostgreSQLColumn.new("arrival_time", nil, "time") endObviously will need some adaptation depending on the database used etc.
-
felipekk
Correcting Jon Leighton:
class Whatever < ActiveRecord::Base ... attr_accessor :arrival_time columns_hash["arrival_time"] = ActiveRecord::ConnectionAdapters::Column.new("arrival_time", nil, "time") endThe above code fixed it for me. Of course, this is an ugly hack. Hoping for a fix soon.
-
Steve Graham
ouch! bitten also.
-
brekaa_osama (at yahoo)
I tried the above fix added by "felipekk"
but didn't workhere is my code
Mobile = Struct.new(:mobile_country_code, :mobile_pure_number) class User attr_accessor :mobile_country_code, :mobile_pure_number columns_hash["mobile_country_code"] = ActiveRecord::ConnectionAdapters::Column.new("mobile_country_code", nil, "character varying(255)") columns_hash["mobile_pure_number"] = ActiveRecord::ConnectionAdapters::Column.new("mobile_pure_number", nil, "character varying(255)") composed_of :mobile, :class_name => 'Mobile', :mapping => [%w(mobile_country_code mobile_country_code), %w(mobile_pure_number mobile_pure_number)], :constructor => Proc.new { |mobile_country_code, mobile_pure_number| Mobile.new(mobile_country_code.to_s.gsub(/^\+/, '00'), mobile_pure_number) } endwhen i try this code in console
u = User.new(:mobile_pure_number => '123491484', :mobile_country_code => '0020') ; puts u.mobile.mobile_pure_numberi get nil
any clue ??
-
Stephan Kaag
Any updates here? This is still an issue?
-
Aditya Sanghi
- State changed from new to wontfix
- Tag changed from 2.x, activerecord to 2.x, activerecord, multiparameter, multiparameter_attributes
I assume that not everyone is sold on defaulting on Time as a fallback for multiparameter attributes.
To specify the class, @felipekk 's response above works and seems like a good way to specify the class for your virtual attribute.
Marking wontfix for now.
Please see #4346 time_select not interpreting the multi-parameter correctly for a comprehensive discussion on other multiparameter and positional parameters issue.
