Perhaps your problem is that using the foreign key "id" means that you are using the "ids" column as a keyword, which is counterintuitive. In this case, the task id 1 believes that it will be associated with the id 1 tag.
If you installed your migrations using the RAILs conventions, I would suggest that you have a column in the tag table that writes task_id. In this case, I think you just need these associations:
class Task < ActiveRecord::Base has_many :logs has_one :tag end class Tag < ActiveRecord::Base belongs_to :task end
Again, this assumes that you have an attribute for tags called "task_id". If you saved it in a non-traditional way, for example, "custom_name_task_id", it will change to
class Task < ActiveRecord::Base has_many :logs has_one :tag, :foreign_key => "custom_name_task_id" end class Tag < ActiveRecord::Base belongs_to :task end
source share