
No type constraint added when querying subclasses in STI
Reported by coxy | February 13th, 2008 @ 03:49 AM
class Article < DataMapper::Base
property :title, :string
end
class SubArticle < Article
property :subtitle, :string
end
---
Article.create :title => "An Article"
SubArticle.create :title => "A SubArticle", :subtitle => "A SubArticle SubTitle"
--
Article.count
=> 2 # seems correct
SubArticle.count
=> 2 # shouldn't there only be 1?
---
Comments and changes to this ticket
-
Michael Boutros February 14th, 2008 @ 07:26 AM
I wrote a fix for this that I believe will fix it for good, but last night I was having a hard with git (my fault, not git's). I'll try to have the patch up here tonight.
-
-
Nick Plante February 15th, 2008 @ 04:58 PM
- Milestone cleared.
- State changed from new to open
-
Michael Boutros February 18th, 2008 @ 07:02 PM
I promise I'll get the patch up here ASAP. I finally figured git out but then my aunt had a baby and I had a trip and now I have a huge test tomorrow, but tomorrow night I'll be free at last!
-
-
coxy February 21st, 2008 @ 03:24 AM
That's great thanks - it works great! I had a 'subclass?' undefined error to start with but adding this to DataMapper::Persistence::ClassMethods seems to have done the trick:
def subclass? superclass != DataMapper::Base end
-
Michael Boutros February 21st, 2008 @ 03:31 PM
Woops, the new patch should work fine. I didn't change the #subclass? method to your way, however, because if I did then models which included Persistence directly wouldn't work.
-
-
Kevin Bullock February 27th, 2008 @ 04:52 PM
The patch doesn't actually work; in the inherited method defined on each class in DM::Persistence.included, you need to define
self.subclass?
instead of justsubclass?
.Updated patch (fix_sti_2.diff) attached.
-
-
Sam Smoot May 2nd, 2008 @ 04:49 AM
- Assigned user set to Adam French
No. We'll apply the patch to 0.3.2 if it still does.
0.9.0 will provide a :scope option for properties, so strictly speaking, this will be resolved by that, not any STI specific code. DM 0.9.0 probably won't actually have STI specific code. Just an inheritance hook to copy properties (already in place), and a property like this:
property :type, Class, :default => lambda { |resource, property| resource.class.name }, :scope => lambda => { |model| { :type => model } }
In the mean-time, Adam, please apply this against DM-SVN.
-
Adam French May 2nd, 2008 @ 03:12 PM
patch applied to 0.3.x r748. Someone please run the specs, my local box is borked
-
Adam French May 2nd, 2008 @ 03:12 PM
- State changed from open to resolved
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »