hi
I have a problen trying to define a composite primary key, which is
composed of a composite foreing key and other foreing key

the code is:

class Turnos; // this class   represent table turnos
class Frentes; //this class represent table frentes
class TipoServicio;// other class whith sample primary key

class TurnosFrentes;//  here composite primary key of foreing key ...
(Turnos and Frentes)

class ServiciosFrentes;   // here is problem to define primary key of
foring key (TurnosFrentes and TiposServivios)


namespace dbo = Wt::Dbo;

template<class F, class S>

class IdComp
{
public:
dbo::ptr<F> first;
dbo::ptr<S> second;


IdComp() { }
IdComp(dbo::ptr<F> f, dbo::ptr<S> s)
: first(f), second(s) { }
 bool operator== (const IdComp& otro) const
{
return first == otro.first && second == otro.second;
}

bool operator< (const IdComp& otro) const
{
if (first < otro.first)
return true;
else if ( first == otro.first)
return second < otro.second;
else
return false;
}


};

template<class F, class S>
std::ostream& operator<< (std::ostream& o, const IdComp<F, S>& iidd)
{
return o << "(" << iidd.first << "," << iidd.second << ")";
}


typedef IdComp< IdComp<Turnos, Frentes> ,TiposServicios > IdCC;


namespace Wt {
  namespace Dbo {

    template <class Action>
    void field(Action& action, IdCC& tf_id, const std::string& name,
          int size = -1)
    {
      belongsTo(action, tf_id.first->first, "turnos", dbo::NotNull);
      belongsTo(action, tf_id.first->second, "frentes", dbo::NotNull);
      belongsTo(action, tf_id.second, "servicios", dbo::NotNull);
    }
  }
}

namespace Wt {
  namespace Dbo {

    template<>
    struct dbo_traits<ServiciosFrentes> : public dbo_default_traits
    {
      typedef IdCC IdType;
      static IdType invalidId() { return IdCC(); }
      static const char *surrogateIdField() { return 0; }
    };
  }
}



class ServiciosFrentes
{
public:

IdCC _id;
std::string _activa;
 template<class Action>
void persist(Action& a)
{
dbo::id(a,_id,"id");
dbo::field(a, _activa, "activa");
}
};





sorry for my english...
thank
------------------------------------------------------------------------------
RSA(R) Conference 2012
Mar 27 - Feb 2
Save $400 by Jan. 27
Register now!
http://p.sf.net/sfu/rsa-sfdev2dev2
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to