async def create_with_nodes_and_edges(
        self,
        db: AsyncSession,
        *,
        obj_in: SyncDagCreate,
        current_user: schemas.User,
        uow: Optional[UnitOfWork] = None,
    ) -> SyncDag:
        """Create a DAG with its nodes and edges."""
        # Create the base DAG object
        db_obj = SyncDag(
            name=obj_in.name,
            description=obj_in.description,
            sync_id=obj_in.sync_id,
            organization_id=current_user.organization_id,
            created_by_email=current_user.email,
            modified_by_email=current_user.email,
        )
        db.add(db_obj)
        await db.flush()  # Flush to get the ID

        # Create nodes
        for node_in in obj_in.nodes:
            node_data = node_in.model_dump()
            db_node = DagNode(
                **node_data,
                dag_id=db_obj.id,
                organization_id=current_user.organization_id,
                created_by_email=current_user.email,
                modified_by_email=current_user.email,
            )
            db.add(db_node)
        await db.flush()

        # Create edges
        for edge_in in obj_in.edges:
            db_edge = DagEdge(
                from_node_id=edge_in.from_node_id,
                to_node_id=edge_in.to_node_id,
                dag_id=db_obj.id,
                organization_id=current_user.organization_id,
                created_by_email=current_user.email,
                modified_by_email=current_user.email,
            )
            db.add(db_edge)

        if not uow:
            await db.commit()
            await db.refresh(db_obj)

        # Reload with relationships
        result = await db.execute(
            select(SyncDag)
            .where(SyncDag.id == db_obj.id)
            .options(
                selectinload(SyncDag.nodes),
                selectinload(SyncDag.edges),
            )
        )
        return result.scalar_one()
Create a DAG with its nodes and edges.
backend/airweave/crud/crud_dag.py