inca / circumflex

[UNMAINTAINED] Circumflex — lightweight Scala-based Web application framework and ORM
http://circumflex.ru
Other
164 stars 35 forks source link

Polymorphism? #12

Open chasm opened 14 years ago

chasm commented 14 years ago

I've been playing around with the Circumflex ORM and it's very nice, but I don't see anything to permit any type of inheritance -- single table or otherwise. Is there a provision for this? I use a lot of traits, often for the purposes of inclusion polymorphism. Not possible? Possible? Planned? Forget it?

Thanks!

inca commented 14 years ago

Planned :)

At the beginning, we've summarized all our experience with STI and Table-Per-Subclass mapping techniques in Hibernate and decided that none of these schemes work more-or-less stable and robust. So we decided that implicit polymorphism described in their documentation is the best solution.

As far as I can tell, nothing stops you from mixing in some trait and then query separate tables several times and collect results into one collection. Your application, thought, might require something more than that. We'll ellaborate on this in 2.0.

Thanks for pointing us into this issue!

chasm commented 14 years ago

My cup runneth over! Implicit would be very cool. I would have been happy enough with nothing more than inclusion. Unfortunately, I need this right now, so I'll have to figure something out. I'll either roll my own (per your suggestion) or maybe I'll try using Squeryl with Circumflex. That might be fun, and I've become reasonably proficient with Squeryl lately.

Do you have a timeline for 2.0?

inca commented 14 years ago

Yepp. It's at least a couple of months, because we have lots to do: from complete reorganization of web framework to adding query statistics, dialects support and testing to ORM. Sorry for inconvenience.

In a meantime, it would be great if you'll share your experience in Squeryl-Circumflex integration.

Thanks!

chasm commented 14 years ago

Sadly, turns out that Squeryl doesn't do inheritance either, so I might as well stick to Circumflex. Any suggestions re how to do a quick roll-your-own single-table inheritance system that will get me by until your brilliant solution can be unveiled to a waiting world? My current plan is to include an automatically set "type" column (don't worry, I won't call it "type"), persist the objects by superclass, and do the casts before saving/after retrieving. What do you think?

Re using Squeryl with Circumflex: nothing to it. Comment out the Circumflex ORM, add the Maven dependency to Squeryl and cglib, and follow the directions on the Squeryl site. Gotta love Circumflex!

<!-- Squeryl -->
<dependency>
  <groupId>org.squeryl</groupId>
  <artifactId>squeryl_2.8.0</artifactId>
  <version>0.9.4beta8</version>
</dependency>

<!-- Needed for Squeryl -->
<dependency>
  <groupId>cglib</groupId>
  <artifactId>cglib-nodep</artifactId>
  <version>2.2</version>
  <scope>compile</scope>
</dependency>

http://squeryl.org/getting-started.html

inca commented 14 years ago

I do not foresee any problems with that. However, I can give you a couple of limitation of using the STI patterns:

Nevertheless, it would be fine if your solution will work for you.

Best regards, Boris Okunskiy

chasm commented 14 years ago

True, but these are all the normal problems with STI. But I'm too lazy so for the moment I'm simplifying things and working around it. Have to get something to show the client very soon. I'll back fit it later.

Any way to do one-to-one relations? And I presume that many-to-many is done using a "bridge" object and two one-to-many relationships? Or did I miss something?

Thanks for all the help. I'm liking Cx a lot and looking forward to 2.0.

Chas.

jdeboer3000 commented 13 years ago

Hi guys,

I am trying to migrate from java+hibernate to scala+circumflex. I was using inheritance strategy in hibernate which worked well. And what about now in circumflex ? It seems you planned to implement something. You talked about "nothing stops you from mixing in some trait and then query separate tables several times and collect results into one collection". How do you do that ? I am not so familiar with scala yet. Could you provide me with an example ? Thanks for your help.