[LRUG] Field definitions in AR models

jc at panagile.com jc at panagile.com
Sat Feb 21 11:36:29 PST 2015


@luke I don't think that changes anything - it's for overriding automatic conversion not for being the one true definition of your attributes.




In theory you could add your own accessors for every attribute but it's not very rails-y and it would still be inaccurate every time you add a row to the DB.




@tom even if AR was just a persistence layer I don't think that changes the original question. You'd still want to understand what attributes you were persisting without having to run code. That AR is inappropriate as your domain model is orthogonal to the fact that understanding the definition of your persistence layer is impossible outside runtime.

On Sat, Feb 21, 2015 at 7:02 PM, Luke Morton <lukemorton.dev at gmail.com>
wrote:

> Does this new feature in active record change things?
> http://edgeapi.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html
> On 20 February 2015 at 08:34, Tom Stuart <tom at codon.com> wrote:
>> On 18 Feb 2015, at 11:33, Thomas Buckley-Houston <tom at tombh.co.uk> wrote:
>> > My problem with poking around the console is that it's counter to the
>> > MVC philosophy of using the Model to describe your domain.
>>
>> I’m surprised nobody’s come out with the obvious-but-unhelpful smartarse
>> answer yet, so I’ll just say it to clear the air:
>>
>> The underlying problem is that Active Record is fit for use as a
>> persistence layer, but not as your domain model. Ideally you would use it
>> for the single concern of trafficking data between the database and a
>> genuine layer of domain objects, which of course can be as rich,
>> descriptive and documented as you like, being the single source of truth
>> for model concerns. In this arrangement the only role of Active Record
>> instances is to map directly onto the database tables and fields, so it
>> makes sense for them to not re-represent this information in code; they’re
>> simply the database reflected in a Ruby mirror. Your actual model objects
>> can be much more than this.
>>
>> Of course experience has shown that this is very difficult to achieve in
>> practice because of the way that Rails and AR work, but hey, why let
>> reality spoil our fun?
>>
>> Cheers,
>> -Tom
>> _______________________________________________
>> Chat mailing list
>> Chat at lists.lrug.org
>> Archives: http://lists.lrug.org/pipermail/chat-lrug.org
>> Manage your subscription: http://lists.lrug.org/options.cgi/chat-lrug.org
>> List info: http://lists.lrug.org/listinfo.cgi/chat-lrug.org
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lrug.org/pipermail/chat-lrug.org/attachments/20150221/11cd09be/attachment-0003.html>


More information about the Chat mailing list