These are chat archives for rails-sqlserver/activerecord-sqlserver-adapter

27th
Jan 2015
Ken Collins
@metaskills
Jan 27 2015 16:53
@sgrif You here?
Sean Griffin
@sgrif
Jan 27 2015 16:53
Yes
Ken Collins
@metaskills
Jan 27 2015 16:54
Off topic question...
Is there a way to tell if a model is has partially loaded attributes in ActiveRecord?
Like if someone used select(:foo).
Sean Griffin
@sgrif
Jan 27 2015 16:54
Yes, but not through public API.
Ken Collins
@metaskills
Jan 27 2015 16:54
Share please :)
Sean Griffin
@sgrif
Jan 27 2015 16:55
Can you give me more context about why you need to do this/
Ken Collins
@metaskills
Jan 27 2015 16:55
Co-worker asking a random question.
Sparked my curiosity. Thought you might know… I’ve done this before.
I just used some other common attribute and if not present in the @attributes hash did a #reload
Sean Griffin
@sgrif
Jan 27 2015 16:56
Well make sure he knows that I suspect that he doesn't actually need to know this, and probably could restructure his code to not care if it was selected or not
Ken Collins
@metaskills
Jan 27 2015 16:56
Wow, you sound just like me :)
Sean Griffin
@sgrif
Jan 27 2015 16:56
Actually there is one way to do it with public API
model.attributes.keys == model.class.attribute_names
Though I wouldn't do that on a performance critical page, attributes is slow
Ken Collins
@metaskills
Jan 27 2015 16:57
Thanks!
I may jump on adapter issues tonight. Took a day off to recharge.
Sean Griffin
@sgrif
Jan 27 2015 16:58
Other options: read_attribute takes a block, and will yield that block if the column exists but was not selected
If you want to reach into internals, @attributes is an instance of AttributeSet, which implements a subset of hash. It has a private method called initialized_attributes which will give you a hash where the key is the name of the attribute, and the value is an Attribute object, rejecting any which were not selected
You can also ask the object if it was selected by calling #initialized?
Lol ok I don't know how I missed this
model.attribute_names
Will only return the selected attributes
Ken Collins
@metaskills
Jan 27 2015 17:03
Wow, I’ll pass on all that gold.
No really, I'm sure we have plenty of sufficient test coverage here
Ken Collins
@metaskills
Jan 27 2015 18:05
Talking about Eileen’s change?
Sean Griffin
@sgrif
Jan 27 2015 18:05
That file in general, lol
Ken Collins
@metaskills
Jan 27 2015 18:05
I have to admit, these areas are so foreign to me.
Sean Griffin
@sgrif
Jan 27 2015 18:06
Me, too
I'm trying to bust this bad boy apart into something a bit more comprehensible.
Ken Collins
@metaskills
Jan 27 2015 18:06
Oh, I do remember table_alias_for
Sean Griffin
@sgrif
Jan 27 2015 18:06
But just looking through how absurdly complex this code is, there is absolutely no way that we have full test coverage
I wonder if I can configure mutant to just fuck with one file, and then run our whole test suite instead of assuming that there's unit test coverage for the class
Ken Collins
@metaskills
Jan 27 2015 18:07
LOL
Given the last commit was a refactor and did not change a test.
Who knows.
Sean Griffin
@sgrif
Jan 27 2015 18:59
😢🔫
Ken Collins
@metaskills
Jan 27 2015 19:35
Was just visiting rails/rails to check something and noticed your Attribute commit.
Very interesting…. I liked that column_types transformed values of the columns hash to types I saw when doing the adapter work. Just noticed how that now enables type_for_attribute to work and then binds become very specific.
Sean Griffin
@sgrif
Jan 27 2015 20:05
Yeah, I'm pretty sure I can have type_for_attribute stop being backed by columns_hash now
Well once I finish changing the consumers of bind_values to consume from bound_attributes instead
Oh and I'll probably change it to a new subclass which takes a table name, as well
So we can look up the SQL type as needed in the connection adapter, and I can fix a bunch of bugs in Relation that I discovered over the last two days
Ideally this will affect you very little, since the parts of the 4 internal adapters that this affects are all basically using copy-pasted code, so I'm going to try and reduce some of this duplication
Sean Griffin
@sgrif
Jan 27 2015 20:18
Screen Shot 2015-01-27 at 1.18.07 PM.png
Ken Collins
@metaskills
Jan 27 2015 20:18
Whoa ho ho!
Sean Griffin
@sgrif
Jan 27 2015 20:19
I think I broke it. Lol