brendon / acts_as_list

An ActiveRecord plugin for managing lists.
http://brendon.github.io/acts_as_list/
MIT License
2.04k stars 355 forks source link

Can I scope it based on a column in another table? #409

Closed SyedMSawaid closed 1 year ago

SyedMSawaid commented 1 year ago

Can I do something like this? Or do I have to replicate the status in SprintTodo as well?

image

brendon commented 1 year ago

You can't reach into other models unfortunately. You could try making a virtual column on the join table that loads this in as though it was on this table? That's just a guess, I'm not sure if it's possible.

SyedMSawaid commented 1 year ago

Can RankedModel help with this or not?

SyedMSawaid commented 1 year ago

Can you give me an example of how can I create a virtual table on join?

brendon commented 1 year ago

RankedModel is largely the same from memory. I'm not too sure about the virtual column thing but stack overflow has some resources depending on your database system. It requires that your virtual column can reach into another table which may or may not be a thing.

Why not just scope to the todo itself? Or perhaps 'status' is actually part of the join and can be moved to the join table?

SyedMSawaid commented 1 year ago

Status can be part of join table. But if I don't have a todo in a sprint? I am not sure how that might work! Any ideas?

brendon commented 1 year ago

I'm afraid that's venturing fairly deep into your specific application design. You might get some help on Stack Overflow though if you ask there.

SyedMSawaid commented 1 year ago

@brendon Check this out! https://stackoverflow.com/questions/75248842/is-there-a-way-to-scope-acts-as-list-based-on-column-in-another-table

brendon commented 1 year ago

Haha yes, I saw that. Convoluted but it'll do the job :D Have you tested it out?

SyedMSawaid commented 1 year ago

Currently, nope. xD It is an answer from StackOverflow so I trust them. If it causes a problem, I'll fix it then. xD

brendon commented 1 year ago

I think it's worth trying, just make sure it can't lead to any SQL injection :)

SyedMSawaid commented 1 year ago

One more thing, if I change the status of Todo, it doesn't automatically update the position of it in SprintTodo. Is there any way to force reset its position?

brendon commented 1 year ago

I don't think that'll easily be possible since all the logic is hanging off the other model and that model isn't even invoked. It's all done using callbacks when creating/updating/deleting the list model. I suppose you could update the Todo via the SprintTodo using nested attributes or something like that?

SyedMSawaid commented 1 year ago

But suppose I change status of Todo from Todo table. Is there any way to force reposition its SprintTodo other than deleting and recreating it?

brendon commented 1 year ago

Not that I'm aware of but feel free to peruse the code. It's not too complicated, just a bit strangely arranged :) All repositioning is handled by callbacks and scope change detection.