handling order with has_many through relationship

I have two models: project and task (for example) with a join model: project_task enabling a has_many through relationship so that tasks may be shared across projects.

I have specified position as an attribute of the project_task model. Now I want to be able to access tasks by their position in the project_tasks table via a given project.

i.e. project.tasks (ordered by the position listed for each task in the project_tasks table).

Is this possible?


I think something like that can help you:

has_many :project_tasks
has_many :tasks, :through => :project_tasks, :order => 'project_tasks.position'

Need Your Help

Java program only writing last line?

java writer

My issue is that with the reader the writer is only outputting what is on the last line of the file and I'm not sure why as far as I know I'm not accidentally closing it or any error similar to that.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.