-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
has_one with sub class does not work #9
Comments
Your example should work. What version of rails you are using? What is your database schema? |
I have the same problem #10 |
I'm using Rails 4.1.4. Here is the brief DB schema: # Photo
create_table "photos", id: :uuid, default: "uuid_generate_v4()", force: true do |t|
t.uuid "user_id"
t.uuid "actable_id"
t.string "actable_type"
t.timestamps
end
# Avatar
create_table :avatars, id: :uuid, default: "uuid_generate_v4()", force: true do |t|
t.boolean :is_profile_avatar
t.timestamps
end It's obvious that it would work if I add a column By the way, it would be clearer if you include the sample DB schema in the README file, as I'm very confused about how the schema looks like when using |
@kidlab did you find anything useful to solve your problem? I really need it urgently... With your example, you can try this, but it is not exactly what you are looking # User.rb
has_many :photos
has_one :avatar, through: :photos, source: :actable, source_type: 'Avatar' |
@se-meridian Thank you for the suggestion. I spent sometimes to walk through the source code of the gem, and I haven't found anything useful yet. It seems to me that it does not support advance feature like that. |
@kidlab, you mentioned about adding column |
I had been waiting for the reply, however, I had better switch to concerns to solve my problems -_- |
It is fully working with sqlite on my specs, there might be a problem with pg or eager loading. I will test it on my first free time. |
@hzamani, can you upload your working example with has_many childs? |
I'm having the same problem as @kidlab. When defining associations to sub models the generated where condition seems to be wrong because is using the sub model table name to reference fields that belongs to the parent model, which leads to a db query error. Here is how I'm modeling part of my application: class MoneyTransaction < ActiveRecord::Base
actable
end
class AirtimeTransaction < ActiveRecord::Base
acts_as :money_transaction
end
class User < ActiveRecord::Base
has_many :airtime_transactions
end The problem comes when I ask for the user's airtime transactions, it fails with this sql error:
I tried to debug the Gem's code but I couldn't find where the problem is. Maybe with this extra information you can now figure out where the issue comes from. Thanks. |
I don't know if its the same problem:
|
if I put |
I've the same issue. The query doesn't inherit correctly of the acting_as model, so column name is wrong. |
same problem |
@hachpai @icemall Could you post your code and db schema? |
This problem is probably fixed in v2.0.3 which was just released. Please open another issue if it still happens with that version. |
Works fine in the new release |
Given these models:
When I call
user.avatar
it raises an error like this:It seems that we haven't supported this feature yet. Is there anyway we can work around this?
Thanks.
The text was updated successfully, but these errors were encountered: