Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    When to use inheritsFrom: in a data source?

    Hi all..

    I'm a little confused about when/where to use an inheritsFrom: construct in an SQL data source. Prior to finding SmartClient I was toying around with another framework (jspresso) which allowed nested data sources of sorts. I envisioned that I could (for instance) create an Address.ds.xml file containing what goes into an address (street address, city, zip,etc) along with the proper field sizes, validation criteria, etc.. Then for an Organization data source, I could say "inheritsFrom: Address" and each instance of my Organization class would also have an address associated with it. When I played around with this last night and used the DataSource tool to create my tables, I did not see any Address "stuff" in my Organization table even though it was set to Inherit from it (but I may have not 'seen' it as it was VERY late). So, a question or two if you don't mind :

    1) Is the "Address" stuff (fields and whatnot) supposed to be pulled in willy nilly into the inheriting class (Organizations in this example) or would Organizations just have a foreign key to an "Address" record?

    2) Is this the proper scenario to use the inheritsFrom: concept or is it meant for some other situation I'm not thinking of?

    Thx!!

    #2
    Typically, Organization and Address would be two separate DataSources that do not inheritFrom each other, and an Organization simply has an Address (or more than one) via a foreignKey relationship, or if it's many-many, via a join table.

    This is the classic relational structure for such a relationship and is typically what an ORM system generates if you have one object inherit from another.

    inheritsFrom has a ton of uses (too many to list here) but this isn't really one of them.

    Comment


      #3
      Ok.. Good to know.. I'll ditch the inheritsFrom: use in my case -- I was figuring I could consolidate some logic/validation stuff since I've got at least three tables (data sources) that will all need an "Address" associated with them -- I figured "Hey -- that's what objects are for!".. I'm not sure if I want to separate the Address stuff out and use a foreign key to access it or ?? I'll figure that out tonight when it's codin' time!

      Are there some examples in the EE showcase making use of the inheritsFrom: feature? Just curious.. Thx!
      Last edited by Rick.F; 13 Feb 2012, 17:57.

      Comment


        #4
        If all of the entities that have an Address add a foreignKey declaration to the same Address DataSource then you will have re-used the Address definition, validation rules, etc.

        The non-EE Showcase has an example of inheritFrom being used to add data to an XML Schema to make it ready for component databinding. Very different domain.

        Comment


          #5
          Thanks! I'll checkout the other example in the non-EE showcase..

          Yes, after I added my comment I realized that I could still have an Address data source to still encapsulate the validation logic, field structure and whatnot and have the other 3 data sources just use foreign keys to them.. I might go that way to not only have the encapsulation but also get used to using foreign keys as well.. :)

          Comment

          Working...
          X