Hey I have a problem with saving data to my sqlite db using active
record.
when i query an object from the db, update a property and save it using
the active record save command it returns true, but nothing happens in
the database.
the user_course object is the right object from the db, it just doesn't
update the data property.
# get user
user = User.find_by_id(req.query["user_id"]);
#get user-course data
user_course =
user.user_courses.find_by_course_id(req.query["course_id"])
# set new data
user_course.data= "test"
# save
user_course.save
Hey I have a problem with saving data to my sqlite db using active
record.
when i query an object from the db, update a property and save it
using
the active record save command it returns true, but nothing happens in
the database.
the user_course object is the right object from the db, it just
doesn't
update the data property.
# get user
user = User.find_by_id(req.query["user_id"]);
#get user-course data
user_course =
user.user_courses.find_by_course_id(req.query["course_id"])
# set new data
user_course.data= "test"
# save
user_course.save
call save! instead of save. This should throw an exception indicating
why it couldn't save which should point you at the direction of the
problem
I'm going to go out on a limb and say that you don't have a problem
creating a new users_courses record.
I would put money that you need only add a primary key to the
users_courses table.
i dont want to have a single primary key, i want a composite one that
consists out of user_id and course_id, like it's done in traditional db
engieering.
I'm going to go out on a limb and say that you don't have a problem
creating a new users_courses record.
I would put money that you need only add a primary key to the
users_courses table.
i dont want to have a single primary key, i want a composite one that
consists out of user_id and course_id, like it's done in traditional
db
engieering.
ActiveRecord doesn't do composite prinmary keys.
Just in case, you know that
# set table name: courses
set_table_name 'courses'
# set primary key: id
set_primary_key 'id'
aren't actually needed.