Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#23 add support for ruby-on-rails implied relationships

closed
John Currier
5
2008-11-04
2006-08-29
jdanilson
No

Our dev teams are using Ruby-on-Rails and the
activeRecord facility therein to develop databases.
While the conventions used in this product fly in the
face of conventional db design and naming conventions,
I'm stuck with the results.

Full documentation is available at
http://rubyonrails.org/api/classes/ActiveRecord/Base.html

From a dba point of view, and using schemaSpy for
documentation, all tables end up as utility tables
because the implied RoR relationships follow a
particular naming convention. For example, all tables
are named as plural, e.g., "things" and the primary key
is always "id int not null" and this is so even if a
realistic pk exists.

Related tables then reference the singular of this
table by a constructed column name <thing>_id. This
becomes interesting when you have a table "persons"
(note the plural) and it's reference "people_id" (one
could argue this should be person_id) but in the RoR
world that's how they do it.

What would be really cool would be some way for
schemaSpy to map this implied relationship, or perhaps
have a flag indicating to look for it. Perhaps someone
smarter than me can look at the RoR active record
documentation and figure out how this could be done.

Discussion

  • John Currier
    John Currier
    2006-08-29

    • assigned_to: nobody --> johncurrier
     
  • John Currier
    John Currier
    2006-08-29

    Logged In: YES
    user_id=1264584

    Are you suggesting some form of dictionary lookup for
    various singular/plurar versions of every column to see if
    it's a possible implied relationship? That sounds painful,
    especially with a global user base.

    But maybe I misunderstood,
    John

     
  • jdanilson
    jdanilson
    2006-08-30

    Logged In: YES
    user_id=1572062

    No, I'm not suggesting a dictionary.

    If you had the following tables in a normal design from
    which you could infer relationships it might be:
    create table order (
    order_id
    ...
    )

    create table line_item (
    order_id
    line_number
    ...
    )

    In the ruby world it would look thus:

    create table orders (
    id
    order_number
    .....
    )
    create table lines (
    id
    order_id [a fk back to id in orders]
    line_number )

    the implied relationship exists because:
    1. there is a table named orders derived from order_id

    clear? as mud? (I hate this derived stuff but I gotta live
    with it unfortunately.)

     
  • John Currier
    John Currier
    2006-08-30

    Logged In: YES
    user_id=1264584

    Okay, now I understand. But given x_id, how would I
    determine the plural of x? Tacking an 's' on works for a
    big chunk of English words, but it's amazing how many
    non-English databases are being analyzed with SchemaSpy.

    Your developers should obviously be shot for the
    people_id/persons thing! If I understand Ruby on Rails
    correctly they made the decision to name the field people
    instead of person. I'm a huge believer in naming things
    correctly. Everything tends to fall into place once you've
    got the right name.

    John

     
  • John Currier
    John Currier
    2008-09-15

    I started to implement something for this, but then I looked at the Ruby docs on this ( http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#M000239 ) and realized that it's nowhere near as simple as it sounds. The plural form of any word in English (ignoring other languages) just isn't simple to derive. Hopefully the XML metadata approach will work if you're unable to use InnoDB with foreign key constraints.

     
  • John Currier
    John Currier
    2008-09-15

    • milestone: 489883 -->
     
  • John Currier
    John Currier
    2008-09-26

    John, can you try the beta (http://schemaspy.sourceforge.net/schemaSpy.jar) with -rails and let me know if it does what you're looking for?

    Note that I'm not sure how to 'tag' these relationships. They're not really implied (explicitly specified by a documented naming convention), but they're not real. Ideas?

    John

     
  • John, I'll put your new version in early next week and let you know how it works out. thanks for continuing this even though we both hate this ror representation.

     
  • John Currier
    John Currier
    2008-09-26

    I've learned to not hate it so much now that I have a better understanding of it. At least it's (hopefully) consistent.

     
  • John C. I ran this over the weekend against all the production systems. No issues but I see some relationships which are not shown. I can tar up the html and send it to you but prefer not to post it on this forum.

    John d.

     
  • John Currier
    John Currier
    2008-09-29

    Sounds good John. Did you see any patterns in the relationships that were missed?

    John

     
  • John Currier
    John Currier
    2008-10-17

    • status: open --> pending
     
  • John Currier
    John Currier
    2008-10-17

    -ror option implemented in release 4.1.0

     
  • jdanilson
    jdanilson
    2008-10-18

    thanks for this enhancement. works great on our ror database schemas.

     
  • jdanilson
    jdanilson
    2008-10-18

    • status: pending --> open
     
  • John Currier
    John Currier
    2008-10-20

    Cool. Glad it works.

     
  • John Currier
    John Currier
    2008-10-20

    • status: open --> pending
     
    • status: pending --> closed
     
  • This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • Victor Engmark
    Victor Engmark
    2012-12-12

    Has this been removed? SchemaSpy reports that "No relationships were detected in the schema", it is no longer in the options list, and I get the following from v5.0.0:

    14:37:14.515 WARNING: SchemaAnalyzer.analyze - Unrecognized option(s): -ror

     
    • PatrickKing
      PatrickKing
      2014-03-25

      The release notes for this feature are out of date, rooting around in the source reveals that the switch for Ruby on Rails databases is now '-rails'. Works fine as of 5.0.0.

       
      Last edit: PatrickKing 2014-03-25