jaystack / jaydata

Notice: this library isn't maintained anymore
http://jaydata.org
GNU General Public License v2.0
352 stars 94 forks source link

Inheritance support #61

Open AresEkb opened 12 years ago

AresEkb commented 12 years ago

Hi!

Thanks for your feedback on stackoverflow!

I need an entity inheritance in my project. For clarity, let the model will be something like: (I'm afraid to talk too much about a real model because it's too genius ;-)

    public class Garage
    {
        public int Id { get; set; }
        public string Owner { get; set; }
        public virtual ICollection<Vehicle> Vehicles { get; set; }
    }

    public abstract class Vehicle
    {
        public int Id { get; set; }
        public string Model { get; set; }

        public int GarageId { get; set; }

        [ForeignKey("GarageId")]
        public virtual Garage Garage { get; set; }
    }

    public class Car : Vehicle
    {
        public string Engine { get; set; }
    }

    public class Bicycle : Vehicle
    {
        public string Color { get; set; }
    }

    public class Train : Vehicle
    {
        public int QuantityOfWagons { get; set; }
    }

And here is a display template:

<script type="text/html" id="garage-template">
  <div class="garage">
    <h3 data-bind="text: Owner"></h3>
    <div class="vehicles" data-bind="foreach: Vehicles">
      <h4 data-bind="text: Model"></h4>
      <div data-bind="template: { name: template }"></div>
    </div>
  </div>
</script>
<script type="text/html" id="car-template">
  Engine: <span data-bind="text: Engine"></span>
</script>
<script type="text/html" id="bicycle-template">
  Color: <span data-bind="text: Color"></span>
</script>
<script type="text/html" id="train-template">
  QuantityOfWagons: <span data-bind="text: QuantityOfWagons"></span>
</script>

Also I need to edit the model: add/remove vehicles, ...

It would be great if JayData could support such scenarios. Thanks!

agdolla commented 12 years ago

Hi Sorry, but we can not support this scenario now, we improve jaydata rapidly so we might support this in the future,

AresEkb commented 12 years ago

Thanks for answer! As I see, a simplest workaround is to flatten a hierarchy:

    public class Vehicle
    {
        public int Id { get; set; }
        public string Model { get; set; }

        public int GarageId { get; set; }

        [ForeignKey("GarageId")]
        public virtual Garage Garage { get; set; }

        public string Engine { get; set; }
        public string Color { get; set; }
        public int QuantityOfWagons { get; set; }

        public string Type { get; set; }
    }
PeterAronZentai commented 12 years ago

Yes, that would help in the short run. We are to support inheritance and polymorphic collections in JayData 1.3, Release date January/2013. Inheritance is somewhat supported already - but is not autodetected from an OData endpoint. Also invariant behavior is not supported - but will be.

AresEkb commented 12 years ago

Thanks! I'll keep developing my app with flatten hierarchy. And I will wait for true inheritance!

hanselsen commented 11 years ago

In your reply you say the inheritance is supported in 1.3 Released January 2013. When will 1.3 be released? Do you know a workaround for the problem? I use OData and JaySvcUtil.

PeterAronZentai commented 11 years ago

1.3 is under heavy testing. We are into releasing this within two weeks. Inheritance support will be there.

From: hanselsen [mailto:notifications@github.com] Sent: Thursday, March 14, 2013 1:37 PM To: jaydata/jaydata Cc: Peter Zentai Subject: Re: [jaydata] Inheritance support (#61)

In your reply you say the inheritance is supported in 1.3 Released January 2013. When will 1.3 be released? Do you know a workaround for the problem? I use OData and JaySvcUtil.

— Reply to this email directly or view it on GitHubhttps://github.com/jaydata/jaydata/issues/61#issuecomment-14899698.

hanselsen commented 11 years ago

Awesome! Thanks for the instant reply.

hanselsen commented 11 years ago

Hello, 3 weeks have been passed. What's the status of the inheritance support?

PeterAronZentai commented 11 years ago

Hi Hans. Thank you for being that patient, it is not too far from now. We are quite behind our schedule since against original plans we wanted to have some major features to be released with the JayData 1.3 server edition (among them is geo indexing and navigation properties over MongoDB). This is why the prolonged Beta phase on 1.3.

As for inheritance currently only the JaySvcUtil generator supports this - so the BaseType OData attribute is handled and entities subclass their respective parent type and not $data.Entity. This in itself will not do a lot of good. The query support is jet to be checked in to github and will support a limited use case for the OData provider: you can have entity sets of inherited types and you'll be able to query in subclass based sets. The client environment provides you with _SubClass_Set entity sets added dynamically to the context.

As for the timeframe now I am bit unsure, since I really don't want to publish a date that is missed to badly again. What is sure that it will be in April (2013 :))