I have a structure something like this:
class User
has_many :dongles
has_many :licences, :through => :dongles
end
class Dongle
has_many :licences
Have you tried with a default scope? First, you can try to add the order in the has_many as I've shown in the User.
class User
has_many :dongles
has_many :licences, :through => :dongles, :order => 'created_at DESC'
end
However, I am not sure if that actually works with a has-many-through association, maybe, if that doesn't work you can try to add it to the association in Dongle instead.
class Dongle
has_many :licences, :order => 'created_at DESC'
belongs_to :user
end
The second option would be to try with a default scope as I've shown in the License.
class Licence
default_scope :order => 'created_at DESC'
belongs_to :dongle
end
after that it should be enough to just get it with user.licenses.find(:first)