[LRUG] Field definitions in AR models

A. Emre Basala emrebasala at gmail.com
Wed Feb 18 09:19:48 PST 2015


Hi

One option might be using "have_db_column" matcher in
(shoulda-matchers gem) to write the rspec tests in model specs.So when
you open a rspec file for a model, you can see the attributes in the
test.
(http://www.rubydoc.info/github/thoughtbot/shoulda-matchers/Shoulda/Matchers/ActiveRecord)



On 18 February 2015 at 16:17, Roland Swingler <roland.swingler at gmail.com> wrote:
>> it seems easier to write the migration approach ... you’d have to write
>> something that diffs what is in the models versus the current state of the
>> schema
>
> Yes - specifically there is no way to tell the difference between renaming a
> column and deleting a column and adding another in this approach.
>
> I think the rationale was Don't Repeat Yourself, and because of the above
> problem you have to put the definition in the Database.
>
> R
>
> On Wed, Feb 18, 2015 at 4:04 PM, Frederick Cheung
> <frederick.cheung at gmail.com> wrote:
>>
>> On 18 February 2015 at 12:00:20, Thomas Buckley-Houston (tom at tombh.co.uk)
>> wrote:
>>
>> Thanks for the replies.
>>
>> I think Tim Diggins most gets what I'm on about, thanks :)
>>
>> My problem with poking around the console is that it's counter to the
>> MVC philosophy of using the Model to describe your domain. Code *as*
>> documentation and all that. In pretty much every other MVC framework
>> and ORM I've come across, fields are described in the model. My
>> question is really curiosity as to why this is? Is AR's fieldless
>> models a known pattern? Or is there a historical reason in AR's
>> development for it?
>>
>>
>> I think for a definitive answer you’d have to ask DHH, but it’s been the
>> way it currently is since migrations were added
>> (https://github.com/rails/rails/commit/eac7cf0b0608132673220d9045b8ff51dc0804e1).
>> Off the top of my head it seems easier to write the migration approach (at
>> least the first implementation of it) than a model based declarative
>> approach where you’d have to write something that diffs what is in the
>> models versus the current state of the schema.
>>
>> Fred
>>
>> _______________________________________________
>> 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
>>
>
>
> _______________________________________________
> 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
>



-- 
Emre Basala
https://www.linkedin.com/pub/emre-basala/63/3a8/814



More information about the Chat mailing list