I have two classes with bidirectional link but the generation of odb files failed with this command :
odb --database mysql --generate-query --generate-schema --std c++14 -I./data-bdd/src/model *.hxx
I have this error (with MySQL and SQLite database type)
error: unable to map C++ type '::__gnu_cxx::new_allocator< ::std::weak_ptr< ::message > >::value_type' used in data member 'm_messages' to a MySQL database type
chat.hxx:29:39: info: use '#pragma db value_type' to specify the database type
I try to add pragma without effect
#pragma db object pointer(std::shared_ptr)
Source files :
In chat.hxx
#include "./root_model_object.hxx"
#include <memory>
#include <string>
#include <vector>
class message;
class user;
/**
* @brief class of chat object in model
*
*/
#pragma db object pointer(std::shared_ptr)
class chat final : public root_model_object {
private:
friend class odb::access;
std::string m_name;
#pragma db value_not_null inverse(m_chat)
std::vector<std::weak_ptr<message>> m_messages;
#pragma db value_not_null inverse(m_chats)
std::vector<std::weak_ptr<user>> m_members;
public:
/**
* @brief Construct a new chat object
*
*/
chat() = default;
/**
* @brief Set the name of object
*
* @param name The name of object
*/
void setName(const std::string &name) { m_name = name; };
/**
* @brief Get the name of object
*
* @return const std::string& the name of object
*/
const std::string &getName() const { return m_name; };
/**
* @brief Set the messages of object
*
* @param messages The messages of object
*/
void setMessages(const std::vector<std::weak_ptr<message>> &messages) {
m_messages = messages;
};
/**
* @brief Get the messages of object
*
* @return const std::vector<std::weak_ptr<message>>& the messages of object
*/
const std::vector<std::weak_ptr<message>> &getMessages() const {
return m_messages;
};
/**
* @brief Set the members of object
*
* @param members The members of object
*/
void setMembers(const std::vector<std::weak_ptr<user>> &members) {
m_members = members;
};
/**
* @brief Get the members of object
*
* @return const std::vector<std::weak_ptr<user>>& the members of object
*/
const std::vector<std::weak_ptr<user>> &getMembers() const {
return m_members;
};
};
#pragma db object(chat)
};
in message.hxx
#include "./chat.hxx"
#include "./root_model_object.hxx"
#include "./user.hxx"
#include <ctime>
#include <memory>
#include <string>
/**
* @brief class of message object in model
*
*/
#pragma db object pointer(std::shared_ptr)
class message final : public root_model_object {
private:
friend class odb::access;
std::string m_content;
#pragma db not_null
std::shared_ptr<user> m_sender;
std::time_t m_send_date;
#pragma db not_null
std::shared_ptr<chat> m_chat;
public:
/**
* @brief Construct a new message object
*
*/
message() = default;
/**
* @brief Set the content of object
*
* @param content The content of object
*/
void setContent(const std::string &content) { m_content = content; };
/**
* @brief Get the content of object
*
* @return const std::string& the content of object
*/
const std::string &getContent() const { return m_content; };
/**
* @brief Set the sender of object
*
* @param sender The sender of object
*/
void setSender(const std::shared_ptr<user> &sender) { m_sender = sender; };
/**
* @brief Get the sender of object
*
* @return const std::shared_ptr<user>& the sender of object
*/
const std::shared_ptr<user> &getSender() const { return m_sender; };
/**
* @brief Set the send_date of object
*
* @param send_date The send_date of object
*/
void setSendDate(const std::time_t &send_date) { m_send_date = send_date; };
/**
* @brief Get the send_date of object
*
* @return const std::time_t& the send_date of object
*/
const std::time_t &getSendDate() const { return m_send_date; };
/**
* @brief Set the chat of object
*
* @param chat The chat of object
*/
void setChat(const std::shared_ptr<chat> &chat) { m_chat = chat; };
/**
* @brief Get the chat of object
*
* @return const std::shared_ptr<chat>& the chat of object
*/
const std::shared_ptr<chat> &getChat() const { return m_chat; };
};
#pragma db object(message)
Thanks a lot if you have the fix of this problem